从PowerShell在文件路径中使用空格运行cmd / c [英] Running cmd /c from PowerShell with spaces in filepath
问题描述
我正在尝试在PowerShell中运行以下命令
I am trying to run the following command in PowerShell
PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat && nuget restore && msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile"
这会产生错误
'C:\Program' is not recognized as an internal or external command.
我的路径中有空格,我正在运行由&&搞砸了一切。我尝试在所有地方都加上引号,但我无法使它正常工作。
My paths have spaces and I'm running several commands seperated by && which is messing everything up. I have tried putting quotes all over the place but I can't get it to work.
如果我只运行命令的第一部分
If i run just the first part of the command
cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat"
它正常工作。但是我也无法使用其他命令。
it works fine. But I can't get the other commands to work too.
推荐答案
我应该阅读 cmd.exe
。
它声明
如果指定了/ C或/ K,则命令行的其余部分将作为新命令在新Shell中处理。如果用引号引起来,则接受由命令分隔符&或&&分隔的多个命令
If /C or /K is specified, then the remainder of the command line is processed as an immediate command in the new shell. Multiple commands separated by the command separator '&' or '&&' are accepted if surrounded by quotes
所以我只需要将命令更改为
So I just had to change my command to
PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat" "&&" nuget restore "&&" msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile
这篇关于从PowerShell在文件路径中使用空格运行cmd / c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!