2017-04-07 182 views
-1

我試圖運行在C以下++程序:運行在C Linux命令++程序

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

BinaryFile是包含/home/test/BinaryFile

當我運行它像這樣的字符串,我得到的以下的輸出:

sh: BinaryFile: No such file or directory 

如果我嘗試以下方法:

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

我得到這些錯誤:

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

我如何能得到這個正常運行?

+0

首先,確保你能在bash的成功運行的命令。 –

回答

0

你需要明確構建您的命令行:

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