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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -