问题描述
我无法使用名称和参数中的空格进行系统调用.例如:
I cannot make system calls with spaces in the names and parameters. For example:
system("c:\program files\something\example.exe c:\my files\example.txt");
我尝试过以我知道的各种方式逃避,但没有任何效果.我试过了:
I have tried escaping in every way I know how, and NOTHING works. I have tried:
system(""c:\program files\something\example.exe" "c:\my files\example.txt"");
和
system("c:\program^ files\something\example.exe c:\my^ files\example.txt");
都不起作用.我仍然得到 'c:program' is not a recongnised internal or external command
Neither work. I still get 'c:program' is not a recongnised internal or external command
这真的让我发疯...我需要调用和传递包含空格的参数.由于我不会讨论的原因,我不能使用短符号.
This is really driving me mad... I need to call and pass parameters that have spaces in them. I cannot use the short notation for reasons I won't go into.
我试过用 ' 引号代替 " 引号,但仍然不起作用.我试过在整个事物周围加上引号,在空格周围加上引号,但不起作用.
I have tried with ' quotes instead of " quotes, still doesn't work. I have tried putting quotes around the whole thing and quotes around the spaces and that doesn't work.
有人知道如何正确地做吗?
Does anyone know how to do it properly?
推荐答案
好的,通过进入 system()
调用弄清楚了:你需要一个由于它在内部调用 cmd/c yourinput
OK, figured it out by stepping into the system()
call: you need an extra set of quotes around the whole thing due the fact that it internally calls cmd /c yourinput
所以这对我有用:
system("""c:\program files\internet explorer\iexplore.exe" "www.stackoverflow.com""");
有点乱,不是吗?
这篇关于Windows C 系统调用,命令中有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!