system() issues on Linux

Apr 27, 2017 at 4:57am
I'm just curious, why wont this work at all?

The command works from the terminal, but not like this from c++ on Linux.
I get this error;
error: expected ‘)’ before ‘Test’
system(" "Test" | mail -s "Test" xxxx@gmail.com");.
1
2
3

 system("echo "Test" | mail -s "Test" xxxx@gmail.com");
Last edited on May 6, 2017 at 8:19am
Apr 27, 2017 at 5:15am
The argument to system has to be one string (const char*), so you might want to use the cstr() function if you have a std::string

Another thing to do is to escape the quotes with \

system("echo \"Test\" | mail -s \"Test\" xxxx@gmail.com");

Note that use of system is a security risk.



Apr 27, 2017 at 5:27am
Thanks so much. i was super confused.
Topic archived. No new replies allowed.