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?
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.
Command-line environments like the Windows Command Prompt and PowerShell use spaces to separate commands and arguments—but file and folder names can also contain spaces. To specify a file path with a space inside it, you'll need to “escape” it.
The command line uses the space character to separate the name of the file being renamed from the new name of the file. When a file contains spaces, it must be surrounded in quotation marks to ensure the proper file is renamed. Otherwise, the command line interprets the words following each space as new file names.
Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With