How to excute shell command and return result string ?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi

I remember here is some C function which can excute shell command and
return the result string .

If I give a string call "ifconfig" , the result string will contain
network IP information .

Do you know this C function name ?   Thank you very much .


Re: How to excute shell command and return result string ?
Quoted text here. Click to load it

Try "execve".  BTW why are you executing a "ifconfig" while you can
access the functionality via standard networking APIs?

Re: How to excute shell command and return result string ?
Quoted text here. Click to load it

system(3) is the high level version that runs the command
via a shell for full shell redirection, etc.
That sets up the pipes (file redirection) that the exec(2) family won't:
you'd have to dup() stdout before exec() to get the output.

Quoted text here. Click to load it


Agreed, use the direct functions when possible
(no need for fork/exec other processes just to get the parameters,
works faster too), but is more work for the programmer.

Site Timeline