简体   繁体   English

如何使用带有空格的路径和命令的“start”在Windows中创建批处理文件

[英]How to create batch file in Windows using “start” with a path and command with spaces

I need to create a batch file which starts multiple console applications in a Windows .cmd file. 我需要创建一个批处理文件,在Windows .cmd文件中启动多个控制台应用程序。 This can be done using the start command. 这可以使用start命令完成。

However, the command has a path in it. 但是,该命令中有一个路径。 I also need to pass paramaters which have spaces as well. 我还需要传递有空格的参数。 How to do this? 这该怎么做?

Eg batch file 例如批处理文件

start "c:\path with spaces\app.exe" param1 "param with spaces"

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. 根据Start命令的帮助,第一个参数是新创建的命令提示符窗口的名称,第二个和第三个参数应分别是应用程序及其参数的路径。 If you add another "" before path to the app, it should work (at least it did for me). 如果你在应用程序的路径之前添加另一个“”,它应该工作(至少它对我来说)。 Use something like this: 使用这样的东西:

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应用程序,则不会显示命令提示符,并且标题无关紧要。

Escaping the path with apostrophes is correct, but the start command takes a parameter containing the title of the new window. 使用撇号转义路径是正确的,但start命令采用包含新窗口标题的参数。 This parameter is detected by the surrounding apostrophes, so your application is not executed. 此参数由周围的撇号检测,因此不会执行您的应用程序。

Try something like this: 尝试这样的事情:

start "Dummy Title" "c:\path with spaces\app.exe" param1 "param with spaces"
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. 我认为第二个qoutation标记阻止命令运行。 After some search below solution save my day: 在解决方案下面的一些搜索之后保存我

start "" CALL "c:\path with spaces\app.exe" "C:\path parameter\param.exe"

Interestingly, it seems that in Windows Embedded Compact 7, you cannot specify a title string. 有趣的是,似乎在Windows Embedded Compact 7中,您无法指定标题字符串。 The first parameter has to be the command or program. 第一个参数必须是命令或程序。

You are to use something like this: 你应该使用这样的东西:

start /d C:\\Windows\\System32\\calc.exe start / d C:\\ Windows \\ System32 \\ calc.exe

start /d "C:\\Program Files\\Mozilla start / d“C:\\ Program Files \\ Mozilla

Firefox" firefox.exe start /d Firefox“firefox.exe start / d

"C:\\Program Files\\Microsoft “C:\\ Program Files \\ Microsoft

Office\\Office12" EXCEL.EXE Office \\ Office12“EXCEL.EXE

Also I advice you to use special batch files editor - Dr.Batcher 另外我建议你使用特殊的批处理文件编辑器--Br.Batcher

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. 我的要求是使用vbscript发送一封电子邮件,需要从windows中的批处理文件调用。 Here is the exact command I am using with no errors. 这是我正在使用的确切命令,没有错误。

START C:\Windows\System32\cscript.exe "C:\Documents and Settings\akapoor\Desktop\Mail.vbs"

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. 当参数传递给它时,命令可能需要处理引号,但这通常不是什么大问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM