有没有可能从不同的文件夹(例如C:\ScriptHome)运行cmd命令,而不是脚本主目录所在的文件夹?
我的意思是,例如:
Cmd /C "C:\Test\test.exe"
- 但是这个exe应该从例如"C:\RunTestExeHere"中调用
基本上,可以在纯cmd中完成,比如cd "C:\RunTestExeHere"
,之后执行
C:\RunTestExeHere>C:\Test\test.exe
- 但是它是否可以在PowerShell中完成呢?
谢谢!
有没有可能从不同的文件夹(例如C:\ScriptHome)运行cmd命令,而不是脚本主目录所在的文件夹?
我的意思是,例如:
Cmd /C "C:\Test\test.exe"
基本上,可以在纯cmd中完成,比如cd "C:\RunTestExeHere"
,之后执行
C:\RunTestExeHere>C:\Test\test.exe
谢谢!
最好的方法是在Push-Location
和Pop-Location
命令之间嵌入您的外部命令。
一个简单的例子:
Push-Location -EA Stop C:\ # You'd use C:\RunTestExeHere instead
cmd /c dir # You'd use & "C:\Test\test.exe" instead
Pop-Location
Start-Process -Wait -NoNewWindow cmd -ArgumentList /c, dir -WorkingDirectory C:\