I am trying to pass a string into the system() shell command function. I am trying to pass a concatenated string into it like so:
string parameters = "Doug";
system("ps -ef|grep " + parameters);
It keeps giving me error because system() takes a char*. How would I go about having the system() function work. I tried putting parameters.c_str() but doesn't work. Thanks!
You need to call c_str() on the result of the concatenation:
system(("ps -ef|grep " + parameters).c_str());
(Note the parentheses.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With