Originally Posted by anu_123
what i need is.. i should be able to use the output further in my code...
so i dont have any handle or variable where this output is stored..
so that i can use it further..
Once I had to use the output of few commands in my C program. I redirected the output of the command in a file and then read that file to extract my required information.
Like, I had to check whether I am connected to other box or not. I found ping to be an easy way to check the connection. If
gives destination host unreachable, then there is some problem with the connection.
I did the following
system( "ping -c 10 192.168.1.61 | grep -i "destination host unreachable" > file.temp ") ;
system( "wc -c file.temp > file2.temp" ) ;
Then I opened the file2.temp using fopen and read it using fgetc. If it gives zero, then we are connected to the box.
$ ping -c 10 192.168.1.61 | grep -i "destination host unreachable" > file.temp # if we are connected then grep will not get any distination host unreachable due to which it won't write a thing on file.temp
$ wc -c file.temp # so wc will tell us that file.temp has 0 bytes
Later, in some other cases I used sed to extract my required info and redirected them to other file, which I later read with usual library functions - fopen, fscanf etc.
Admittedly, this is not a proper or an ingenious way
Perhaps, gurus at LQ will share a proper method.