使用 C++ 中的 system()在 Windows 上,为什么需要两个引号才能调用另一个目录中的程序?
我的 utils 文件夹中有 find.exe 程序。这不起作用:
system("\"utils/find.exe\"");
我得到的只是
'utils' is not recognized as an internal or external command,
operable program or batch file.
但是,由于某种原因,这有效:
system("\"\"utils/find.exe\"\"");
回显单引号字符串
system("echo \"utils/find.exe\"");
输出
"utils/find.exe"
......那么为什么我需要两个引号?
I have the find.exe program in my utils folder. This does not work:
system("\"utils/find.exe\"");
All I get is
'utils' is not recognized as an internal or external command,
operable program or batch file.
However, for some reason this works:
system("\"\"utils/find.exe\"\"");
Echoing the single quoted string
system("echo \"utils/find.exe\"");
outputs
"utils/find.exe"
... so why do I need two quotes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您使用的是 Windows,因为您正在尝试执行 .exe 文件。因此,不要写“utils/find.exe”,而是尝试写“utils\find.exe”。 Windows 上的分隔字符是“\”,因此它可能会将“utils”视为命令,因为“/”被忽略。
I assume you're on windows because you're trying to execute an .exe file. So, instead of writting "utils/find.exe", try to write "utils\find.exe". The delimiting character on windows is '\', so it probably sees "utils" as a command since '/' is ignored.
也许
system()
正在将你的命令行传递给shell,例如cmd.exe
,它也需要引用?Perhaps
system()
is passing your command line to the shell, e.g.cmd.exe
, which also needs quoting?即使您可以在 Windows 中使用 / 和 \ 作为目录分隔符,命令处理器也会尝试将以 / 开头的任何内容解释为开关。试试这个:
Even though you can use both / and \ as directory separators in Windows, the command processor will try to interpret anything starting with a / as a switch. Try this: