繁体   English   中英

C ++:未生成系统命令的输出文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM