J
JLK
I'm having a bit of a time with the following code. I can script this
real easy in Bash but I'm trying to practice my C++:
*******************************************************
#include <iostream>
#include <string>
using namespace std;
int main () {
string user = "fred";
string cmd;
cmd = "curl -d userid=" + user + "&press=submit http://URL";
cout << "command = " << cmd << endl;
cout << "command = " << cmd.c_str() << endl;
system(cmd.c_str());
return 0;
}
*******************************************************
If you run it you'll notice that both of the couts will produce the
full line ok. However, if I try to pass either one to system() it will
fail as nothing past "curl -d userid=" gets appended. How can you
pass variables such as parameters to system() ??
real easy in Bash but I'm trying to practice my C++:
*******************************************************
#include <iostream>
#include <string>
using namespace std;
int main () {
string user = "fred";
string cmd;
cmd = "curl -d userid=" + user + "&press=submit http://URL";
cout << "command = " << cmd << endl;
cout << "command = " << cmd.c_str() << endl;
system(cmd.c_str());
return 0;
}
*******************************************************
If you run it you'll notice that both of the couts will produce the
full line ok. However, if I try to pass either one to system() it will
fail as nothing past "curl -d userid=" gets appended. How can you
pass variables such as parameters to system() ??