Calling PowerShell from MATLAB: executing commands from within script

조회 수: 11 (최근 30일)
Peyton Johnson
Peyton Johnson 2020년 5월 14일
댓글: Rik 2020년 5월 20일
My goal is to call PowerShell from MATLAB and set a file path from within the script that I am writing. I have as of now:
!PowerShell "Set-Location C:\Program Files (x86)"
The error that is displayed is as follows:
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:32
+ Set-Location C:\Program Files (x86)
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Note: !PowerShell works for me, and I can cd to the file path I want to go to in the command window. However, I want to set the file path in the script.
  댓글 수: 2
Peyton Johnson
Peyton Johnson 2020년 5월 20일
I forgot to ask a question. Is it possible to "cd" to a filepath, using Powershell, in the script and not in command window?
Rik
Rik 2020년 5월 20일
Don't you need to enclose paths that have a space in them with double quotes?
And for the question in your comment: I suspect every time you call PowerShell through the system command, Matlab will create a new instance. So as long as you can fit everything in a single call you can cd to your hearts' content.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by