[英]C++: Output file of system command not generated
我正在尝试从我的代码运行shell命令。 但是,不会生成输出文件(ts.dat)。 有人可以让我知道如何解决这个问题吗?
string cmd1, input;
cout << "Enter the input file name: ";
cin >> input;
cmd1 = "grep 'DYNA>' input | cut -c9-14 > ts.dat";
system((cmd1).c_str());
cmd1="grep 'DYNA>' "+input+" | cut -c9-14 > ts.dat";
将input
放在引号内将使编译器将其解析为字符串而不是变量。
编辑此行:
cmd1="grep 'DYNA>' input | cut -c9-14 > ts.dat";
对此:
cmd1="grep 'DYNA>' " + input + " | cut -c9-14 > ts.dat";
您实际上需要使用input
字符串中的值。 当前使用代码的方式只是在字符串中input
单词input
,而不使用字符串中存储的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.