could this happen.. ??

Go down

could this happen.. ??

Post  vijay on 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

View user profile

Back to top Go down

Re: could this happen.. ??

Post  ankurgutpa on 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
avatar
ankurgutpa

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

View user profile

Back to top Go down

Back to top

- Similar topics

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