How can I execute the command line "asterisk -rx "reload"" in c++? Please help. I need an example. I am working on ubuntu server and I want to execute this command line from a user (inside a webservice).
Need help Appreciate
How can I execute the command line "asterisk -rx "reload"" in c++? Please help. I need an example. I am working on ubuntu server and I want to execute this command line from a user (inside a webservice).
Need help Appreciate
Sounds like a trivial use-case for the system() function:
system("asterisk -rx reload");
If you need very fine-grained control of the child process there are better ways, but this is simple to get going.
This call starts a shell (such as bash) to run the command, which is why I removed the quotes around reload; they're pointless for a single word and will be removed by the shell and never seen by the started program, anyway.
system function must have the correct privileges to execute the asterisk program. For example, if your program is running as a normal user, but asterisk requires a root user, then the system call will not work because the your program is not allowed to execute asterisk.system("asterisk -rx \"reload\"") would probably work, if you don't need standard output or error from the process.
If you need results from the process, here is an example of using C's popen(), or you could look at Boost.Process for a C++ approach.