Reputation: 5
I am trying to run a shell command from my code. However, the output file (ts.dat) is not generated. Can somebody let me know how to solve this problem?
string cmd1, input;
cout << "Enter the input file name: ";
cin >> input;
cmd1 = "grep 'DYNA>' input | cut -c9-14 > ts.dat";
system((cmd1).c_str());
Upvotes: 1
Views: 106
Reputation: 709
cmd1="grep 'DYNA>' "+input+" | cut -c9-14 > ts.dat";
Placing input
inside the quotes will let the compiler parse it as a string instead of a variable.
Upvotes: 1
Reputation: 17428
Edit this line:
cmd1="grep 'DYNA>' input | cut -c9-14 > ts.dat";
To this:
cmd1="grep 'DYNA>' " + input + " | cut -c9-14 > ts.dat";
You need to actually use the value from the input
string. The way you have your code currently, you are just writing the word input
in your string and not using the value that is stored in the string.
Upvotes: 1