How to excute shell command and return result string ?

Mar 11, 2009 2 Replies

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 .



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

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.

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.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required