c++ - system() question
May 25, 2008 at 3:21am UTC
pretty much finished getting my little app to run and have
a question about the system() command.
i'm using a command line app called nconvert to process
photos. i use a command similar to this from the command
line:
nconvert -out outformat -o name_of_processed_file name_of_original_photo
there are three variables i use in the command line
scripting i have:
outformat
name_of_processed_file
name_of_original_photo
i tried this to get system() to execute nconvert but had
a problem with the variables:
system("nconvert -o outformat -o name_of_processed_file name_of_original_photo" )
i assume the quotation marks around the nconvert command
are the source of the problem.
how do i use system() with variables for the parameters
of the command line app?
thanks,
BabaG
Last edited on May 25, 2008 at 3:21am UTC
May 25, 2008 at 4:30am UTC
got a reply elsewhere suggesting making a big string and using
that within the system() command. just tried it and got an error.
i declared:
string nconvert_param = "nconvert -out " + outformat + " -o " + name_of_processed_file + " " + name_of_original_photo
which i can cout to the screen and prints just as it should.
compiling, however, gives an error about not being able to
convert 'std::string' to 'const char*' for the line in my code:
system( nconvert_param );
tried declaring string nconvert_param' as 'const char nconvert_param'
but that produced a different error.
what did i get wrong here?
thanks again,
BabaG
May 25, 2008 at 5:01am UTC
You are closer than you think. system () takes a (char*), so turn your string into one:
system( nconvert_param.c_str() );
Hope this helps.
Last edited on May 25, 2008 at 5:01am UTC
May 26, 2008 at 5:08pm UTC
thanks Duoas!
Topic archived. No new replies allowed.