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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -