Getting screen return from system()?
when using system() is there a way I can capture the result of it? (ex: the actual error/output on the screen)
Or is there a better way to execute shell commands? In most cases if I can I use built in functions to accomplish the task that I'm using system() for, but in some cases I have to use system(). My program is to administer a Linux server so it does stuff like create/edit/delete users, etc.
One way I'm thinking is I can pipe it to a temp file then read the file, but that's kinda messy, I'm wondering if there's a better way.
Re: Getting screen return from system()?
why not do it directly without commands
Re: Getting screen return from system()?
Re: Getting screen return from system()?
Quote:
Originally Posted by
cj-wijtmans
why not do it directly without commands
Not everything is possible to do directly in C++ (that I know of), such as creating/editing shell users, restarting services, running a command like rsync, etc.
Re: Getting screen return from system()?
Quote:
Originally Posted by
j0nas
I'll check that out. I'm guessing the FILE is a file stream I can read that represents the output? Is this correct?
Re: Getting screen return from system()?
Quote:
Originally Posted by
Red Squirrel
I'll check that out. I'm guessing the FILE is a file stream I can read that represents the output? Is this correct?
Yes, I think so. Take a look at the opengroup documentation here and the sample example that reads the output from the 'ls' command - opengroup - popen().