Instead of what?
I do not create or open a file. All I need is to get the answer of any command from the command line into a string, "pwd" is just an example.
it works for some commands for example pwd, ifconfig, netstat, etc; but it does not get some answers such as "No such file or directory" when I used "gcc nonExistent.c" or "route help".
Any ideas?
netstat, ifconfig are not in your PATH. Try with providing full path or Might be you need supreuser permissions.
First try these commands on your promopt/shell.