Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

windows C system call with spaces in command

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...