OK, before I tear the cow book into little bits and fling them out the window, how do I just run a system command using something like system() but pass a variable to it? And get the output back? Everything else works fine...
The command you want to run must be a char*, so you have to use string-handling functions to create the argument before you hand it to anything like system(). There are a couple of different ways. Look at strncat for one.
You can't get the output of a command directly from system(), as it will only return the exit code of your command. Try popen() instead.
Sorry, what I meant is that if you want to use a variable in the argument passed to any of those functions, you may want to assemble a single command string from the variable and other strings, then pass that string.
To get the output back, the official command is 'popen' (short for 'pipe open'). Look that up, and get familiar with it. You'll note that the function is potentially insecure when called in certain ways, but there's documentation about that online too, if you're concerned. Good luck!
no subject
Date: 2003-12-02 05:38 am (UTC)You can't get the output of a command directly from system(), as it will only return the exit code of your command. Try popen() instead.
no subject
Date: 2003-12-02 06:45 am (UTC)no subject
Date: 2003-12-02 08:45 am (UTC)Between strnfoo and popen, you should be all set.
no subject
Date: 2003-12-02 06:50 am (UTC)no subject
Date: 2003-12-02 06:52 am (UTC)