Computer Club MNNIT
Would you like to react to this message? Create an account in a few clicks or log in to continue.

could this happen.. ??

2 posters

Go down

could this happen.. ?? Empty could this happen.. ??

Post  vijay Mon Aug 18, 2008 7:19 am

consider this output...
Code:

$ ./prog
IITK
IITD
IITM
$

and now this....
Code:

$./prog | wc -l
IITK
IITD
IITM
0
$

in the second case... the output was expected to be ..
Code:

$./prog | wc -l
3
$

what is happening here...?? modify this shell sequence so that expected output is printed....

vijay

Posts : 6
Join date : 2008-08-18

Back to top Go down

could this happen.. ?? Empty Re: could this happen.. ??

Post  ankurgutpa Wed Sep 17, 2008 4:46 pm

one of the possible reason could be:
in prog file the o/p has been directed to stderr ,as pipe transform stdoutput of cmd to it;s left to standard input of command to it's right w/o touching it's srderr
contents of prog may include:
Code:

echo IITK 1>&2
echo IITD 1>&2
echo IITM 1>&2
stdoutput is redirected to stderr hence ./prog| wc -l is not producing desired result.
To get desired result stderr should be redirected to stdinput whenever ./prog is used ie
Code:

$ ./prog 2>&1 | wc -l
$ 3
cheers
ankurgutpa
ankurgutpa

Posts : 44
Join date : 2008-08-10
Age : 36
Location : Tandon 72

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum