Quick Question

C

Carter

How do you make the output of a c++ program be interpreted as a UNIX
command? Example, what would a program that executed ls look like?
 
V

Victor Bazarov

Carter said:
How do you make the output of a c++ program be interpreted as a UNIX
command? Example, what would a program that executed ls look like?

You should probably use 'system' function.
 
M

Mike Wahler

Carter said:
How do you make the output of a c++ program be interpreted as a UNIX
command? Example, what would a program that executed ls look like?

#include <cstdlib>
#include <iostream>

int main()
{
int status = EXIT_SUCCESS;

if(system(NULL))
system("ls");
else
{
std::cerr << "Command processor not available\n";
status = EXIT_FAILURE;
}

return status;
}


-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top