system() issues on Linux

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
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.



Thanks so much. i was super confused.
Topic archived. No new replies allowed.