Running a linux command in C++ program -


i trying run following in c++ program:

string cmd("strings -n 3 < binaryfile > ascii.txt"); system(cmd.c_str(); 

binaryfile string contains /home/test/binaryfile

when run so, following output:

sh: binaryfile: no such file or directory 

if try following:

string cmd("strings -n 3 < binaryfile.c_str() > ascii.txt"); system(cmd.c_str(); 

i these errors:

sh -c: line 0: syntax error near unexpected token '(' sh -c: line 0: 'strings -n 3 < binaryfile.c_str() > ascii.txt 

how can run properly?

you need construct command line explicitly:

string cmd("strings -n 3 < " + binaryfile + " > ascii.txt"); system(cmd.c_str()); 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -