我知道这是一个奇怪的用例,但我需要在新流程中像这样执行,并且要一行完成。我花了很长时间才到达这个地方。为此,我已经把头发扯了好几个小时了……请帮助!
此命令在powershell和cmd中有效:
powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file C:\Temp\Test.ps1').Id"
此命令可在Powershell中使用,但不能在cmd中使用(找不到文件):powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test.ps1`"').Id"
当我在文件名中添加空格时,在PowerShell或cmd中找不到该文件(该文件确实存在):powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test 1.ps1`"').Id"
最佳答案
您可以从命令提示符直接运行它:
start "" powershell -file "C:\Temp\test.ps1"
这将在新窗口中启动该过程。
关于powershell - 如果文件名包含空格,则嵌入式PowerShell命令将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000941/