为什么不能在 cmd.exe 可执行文件的选项两边加上引号?
在一些自动化测试中,我在给可执行文件的每个命令周围加上双引号,例如,
notepad "hello.txt"
这可以正常工作。另外,如果我尝试对其他可执行文件进行相同的操作,这似乎总是有效。但是,以下内容在 Windows 7 上不起作用:
cmd.exe "/c" "echo hello"
问题不在于“echo hello”周围的引号,但它似乎不喜欢 /c 选项周围的引号。我得到的只是以下输出:
'"echo hello' is not recognized as an internal or external command, operable program or batch file.
Windows 是否以不同方式处理 cmd.exe?
In some automated tests I put double-quotes around every command given to an executable, e.g.
notepad "hello.txt"
This works correctly. Also if I try the same with other executables this always seem to work. However, the following doesn't work on Windows 7:
cmd.exe "/c" "echo hello"
The problem isn't the quotes around "echo hello", but it doesn't seem to like the quotes around the /c option. All I get is the following output:
'"echo hello' is not recognized as an internal or external command, operable program or batch file.
Is cmd.exe handled differently by Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“hello.txt”是一个文件名,通常您只引用文件名/路径(以及可能包含空格的其他参数)
,是的,cmd.exe 可能有一些特殊处理,您可以使用 /S 来更改引用处理。
恕我直言,“/c”无论如何都是不好的做法,看起来你想在当前驱动器的根目录下执行 c.exe
"hello.txt" is a filename, and in general you only quote filenames/paths (and other parameters that might contain spaces)
And yes, cmd.exe probably has some special handling, you can use /S to change the quote handling.
IMHO "/c" is bad practice anyway, it looks like you want to execute c.exe at the root of the current drive