Hi,
In my c program, i call the system("pgrep -c thttpd");
the return value is //-- 0 - One or more processes matched the criteria. //-- 1 - No process matched the criteria but the output on the screen is 2. how can i capture this output? Thanks in advance Alex
Hi!
You called system("...") in your C program. First of all, the returned value has to do with the exit status of the program run under system, not the output of the command!
Second: Every process (process is a running program) has it's standard output to send the output and a standard error to send error messages. In your case the messages possibly are error messages of "pgrep" process and are sent to your terminal (the default standard error chanel). To check thsi fact run your program as:
where your_program is the name of the executable, panos1 is a file to use as standard output and panos2 is a file to use as standard error. After running the above command, you probably have the messages in panos2 as this file is used as standard error for your executable and inherited to child processes too (e.g. pgrep run under system as a chile process).
Third: To capture the standard output (or the the standard error) of a process run as child of another process you have to use the pipe system calls or functions; see the manual pages in popen, pipe etc. It's not easy and some experience in the C language is needed.
Hi Guys,
Please help me.. it is urgent. I am writing a perl script to capture command output and redirect it to a logfile.At the same i want to check the return code of the command and log it if the command is not succesful in my logfile.. Here is my code, it is working but system command inside... (2 Replies)
Hi
we are calling kill -9 $pid command from bash script it gives below output, but we need to hide the output. i tried /dev/null but ni luck. is there any alternate way to schive this.
../kill_scr.sh: line 42: 1891 Killed /tmp/anr_rest_mul_wc.sh
Soalris 10.
... (2 Replies)
hey guys in only new to scripting as such, but i have a problem.
i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output.
this this what im doing:
-bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc=
# base... (1 Reply)
Hi everybody,
I am working on a bigger awk script in which one part is comparing the size of two files.
I want to evaluate which file is bigger and then just save the bigger one.
I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Hi,
I am new to C and have a little problem.
I am not planning to be a C expert, but this would be nice to understand.
The problem is that a 'system' call prints it output to stdout, when I do not expect this.
This is the program:
trial.c
#include <ctype.h>
#include <unistd.h>... (5 Replies)
Hi there
could anybody point me in the right direction when it comes to looping through the output of a system command in perl (i.e. df -k) doing a test against each line to see if it matches?
for example if i have a df -k output like this and I wanted to grab the lines that matched "sda" or... (3 Replies)
Hi, im in need if wisdom here guys...
How could I store the output of commands like ping integrally directly into a array??? I'll be using system() to run the commands but how can I send the output to an array??? cuz I need to store it so that I can later copy the array's content to a buffer... (5 Replies)
hello,
I want to print my output into a file inside of awk, but I don't know it could wokr with using system (piping the $1-4 to another shellskript):
cat file.txt |awk '{ if ($5==2) {dataname=$1 "_" $2 "_" $3 "_" $4 "_typing.rad"
befehl=".gen_test " $7 " " $8 " " $8
system(befehl) >... (5 Replies)
Hi,
From the above output of df command I need to parse only 43G (available space) and display it.
root@localhost:> df -h /vol1/joy
Filesystem Size Used Avail Capacity Mounted on
/vol1/joy 180G 137G 43G 76% ... (3 Replies)