LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   terminal command in c program (https://www.linuxquestions.org/questions/linux-general-1/terminal-command-in-c-program-809307/)

eng_suha 05-21-2010 09:04 AM

terminal command in c program
 
hi guys

I want to design c program can run terminal command and put the output of command into file... How can i do this ?

for example :

string s = " iwlist scan "

and when i run the programm this command applied and put the output into specific file

plz help me

rweaver 05-21-2010 11:09 AM

Been a while since I did c, but i believe you're looking for the "system" call, as for putting it in a specific file... you could just specify it in the command itself--

system("/usr/local/sbin/command > /tmp/out-file");

Generally speaking, its far easier to write a bash or perl script than a c program when you're heavily interacting with system and you may want to look at those routes depending on what the end goal is here.


All times are GMT -5. The time now is 11:41 AM.