windows C system call with spaces in command

隐身守侯 提交于 2019-12-17 12:43:43

问题


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\"");

and

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

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?


回答1:


Edit: 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

So this works for me:

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

A bit of a mess, isn't it?



来源:https://stackoverflow.com/questions/2642551/windows-c-system-call-with-spaces-in-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!