【问题标题】:windows C system call with spaces in commandWindows C 系统调用,命令中有空格
【发布时间】:2011-02-08 05:03:38
【问题描述】:

我无法在名称和参数中使用空格进行系统调用。例如:

system("c:\\program files\\something\\example.exe c:\\my files\\example.txt");

我已经尝试了各种我知道的方式来逃避,但没有任何效果。我试过了:

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 reconnised internal or external command

这真的让我发疯......我需要调用并传递其中包含空格的参数。由于我不会详细介绍的原因,我不能使用简短的符号。

我尝试使用 ' 引号而不是 " 引号,但仍然不起作用。我尝试在整个内容周围加上引号并在空格周围加上引号,但这不起作用。

有谁知道正确的做法吗?

【问题讨论】:

    标签: c windows command-line escaping


    【解决方案1】:

    编辑: 好的,通过进入system() 调用来解决这个问题:由于它在内部调用 cmd /c,因此您需要在整个事情周围加上一组额外的引号 你的意见

    所以这对我有用:

    system("\"\"c:\\program files\\internet explorer\\iexplore.exe\" \"www.stackoverflow.com\"\"");
    

    有点乱,不是吗?

    【讨论】:

    • 糟糕,我一直在使用斜杠。我需要它与系统一起工作的原因是因为我也在使用 _open 等。
    • 已编辑 - 尝试使用双引号。
    • 这个怎么样? system(&("C:\Program Files (x86)\Internet Explorer\iexplore.exe") "www.stackoverflow.com") 参考:blogs.technet.com/b/heyscriptingguy/archive/2012/08/07/…
    • 这是 Windows 特有的事情,还是 UNIX 也有这种行为?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    相关资源
    最近更新 更多