如何使用带路径的“开始”和带空格的命令在 Windows 中创建批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/72671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create batch file in Windows using "start" with a path and command with spaces
提问by Andy
I need to create a batch file which starts multiple console applications in a Windows .cmd file. This can be done using the start command.
我需要创建一个批处理文件,它在 Windows .cmd 文件中启动多个控制台应用程序。这可以使用 start 命令完成。
However, the command has a path in it. I also need to pass paramaters which have spaces as well. How to do this?
但是,该命令中有一个路径。我还需要传递也有空格的参数。这该怎么做?
E.g. batch file
例如批处理文件
start "c:\path with spaces\app.exe" param1 "param with spaces"
回答by Andy
Actually, his example won't work (although at first I thought that it would, too). Based on the help for the Start command, the first parameter is the name of the newly created Command Prompt window, and the second and third should be the path to the application and its parameters, respectively. If you add another "" before path to the app, it should work (at least it did for me). Use something like this:
实际上,他的例子是行不通的(虽然一开始我也认为行得通)。根据 Start 命令的帮助,第一个参数是新创建的命令提示符窗口的名称,第二个和第三个应该分别是应用程序及其参数的路径。如果您在应用程序路径之前添加另一个“”,它应该可以工作(至少对我来说是这样)。使用这样的东西:
start "" "c:\path with spaces\app.exe" param1 "param with spaces"
You can change the first argument to be whatever you want the title of the new command prompt to be. If it's a Windows app that is created, then the command prompt won't be displayed, and the title won't matter.
您可以将第一个参数更改为您希望新命令提示符的标题。如果它是创建的 Windows 应用程序,则不会显示命令提示符,标题也无关紧要。
回答by Steffen
Escaping the path with apostrophes is correct, but the start command takes a parameter containing the title of the new window. This parameter is detected by the surrounding apostrophes, so your application is not executed.
使用撇号转义路径是正确的,但 start 命令采用包含新窗口标题的参数。此参数由周围的撇号检测到,因此不会执行您的应用程序。
Try something like this:
尝试这样的事情:
start "Dummy Title" "c:\path with spaces\app.exe" param1 "param with spaces"
回答by Mustafa Kemal
start "" "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
When I used above suggestion, I've got:
当我使用上述建议时,我得到了:
'c:\path' is not recognized a an internal or external command, operable program or batch file.
'c:\path' 不是内部或外部命令,也不是可运行的程序或批处理文件。
I think second qoutation mark prevent command to run. After some search below solution save my day:
我认为第二个 qoutation 标记阻止命令运行。经过以下解决方案的一些搜索,拯救我的一天:
start "" CALL "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
回答by Mark Agate
Interestingly, it seems that in Windows Embedded Compact 7, you cannot specify a title string. The first parameter has to be the command or program.
有趣的是,似乎在 Windows Embedded Compact 7 中,您无法指定标题字符串。第一个参数必须是命令或程序。
回答by user243871
You are to use something like this:
你要使用这样的东西:
start /d C:\Windows\System32\calc.exe
start /d "C:\Program Files\Mozilla
Firefox" firefox.exe start /d
"C:\Program Files\Microsoft
Office\Office12" EXCEL.EXE
启动 /d C:\Windows\System32\calc.exe
开始 /d "C:\Program Files\Mozilla
Firefox" firefox.exe start /d
"C:\Program Files\Microsoft
Office\Office12" EXCEL.EXE
Also I advice you to use special batch files editor - Dr.Batcher
另外我建议你使用特殊的批处理文件编辑器 - Dr.Batcher
回答by Curro
Surrounding the path and the argument with spaces inside quotes as in your example should do. The command may need to handle the quotes when the parameters are passed to it, but it usually is not a big deal.
在您的示例中,用引号内的空格包围路径和参数应该这样做。命令在传递参数时可能需要处理引号,但这通常没什么大不了的。
回答by Anupam Kapoor
I researched successfully and it is working fine for me. My requirement is to sent an email using vbscript which needs to be call from a batch file in windows. Here is the exact command I am using with no errors.
我研究成功,它对我来说很好用。我的要求是使用需要从 Windows 中的批处理文件调用的 vbscript 发送电子邮件。这是我使用的确切命令,没有错误。
START C:\Windows\System32\cscript.exe "C:\Documents and Settings\akapoor\Desktop\Mail.vbs"