为什么Windows START命令不能在参数AND路径中使用空格? [英] Why does windows START command not work with spaces in arguments AND path?

查看:106
本文介绍了为什么Windows START命令不能在参数AND路径中使用空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此命令有效

START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2

但是这两个都失败了!

START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4
START /b /wait "Dummy title" "C:\tmp\test runner2.bat" arg1 arg2 "arg 3"

错误是:

'C:\tmp\test' is not recognized as an internal or external command, operable program or batch file.

显然,这与"围绕参数有关,但是为什么以及如何解决此问题?

Obviously it has something to do with " surounding the arguments, but why and how do I work around this?

相关问题:

  • How to create batch file in Windows using "start" with a path and command with spaces
  • Can I use the "start" command with spaces in the path?

推荐答案

这是START命令的已知错误.
如果命令和参数中都包含空格,并尝试使用引号将其括起来,则它将失败.

It's a known bug of the START command.
If you have spaces in both, the command and of the parameters and try to handle them with quotes, it fails.

首先使用START命令检查完整命令是否存在.
但随后它仅开始第一部分.

First the START command check if the full command exists.
But then it starts only the first part.

在您的情况下,它会查找"C:\tmp\test runner2.bat",但尝试启动C:\tmp\test.

In your case it looks for "C:\tmp\test runner2.bat" but try to start C:\tmp\test.

将命令替换为CALL

START /b /wait "Dummy title" CALL "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4

START使用cmd /k开始新过程.
这就是导致不当行为的原因. Paul Groke提到了一个事实,即只有在批处理文件中才会出现这种情况.
Exe文件将直接执行,因此不会受到cmd.exe错误的影响.

The START uses cmd /k to start the new process.
And that is the cause for the misbehaviour.
Paul Groke mentioned the fact, that this only occours when it's a batch file.
Exe files will be executed directly and so they are not affected by the cmd.exe bug.

以您的情况

C:\Windows\system32\cmd.exe  /K "C:\tmp\test runner2.bat" arg1 arg2 "arg 3" arg4

cmd /kcmd /c的帮助说明,在这种情况下,第一引号和最后一个引号均被删除.

And the help of cmd /k and cmd /c explains, that in this case the first and last quote are removed.

这篇关于为什么Windows START命令不能在参数AND路径中使用空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆