Skip to content
Advertisement

calling std::system with parameter containing space in double quotes

I need to call a linux std::system call with parameter than contain string with spaces. In order to process it correctly using argc / argv I want to pass it with double quotes.

std::string cmdline = “myprogram -d “I am a sting”” ;

if I cout this string I get good results.

When I send it to std::system(cmdline) and look at ps -ef I get myprogram -d I am a string

How can I keep “I am a string” as a single parameter for myprogram ?

Advertisement

Answer

No problem:

JavaScript

(tested in Cygwin)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement