could this happen.. ??
Page 1 of 1 • Share •
could this happen.. ??
consider this output...
and now this....
in the second case... the output was expected to be ..
what is happening here...?? modify this shell sequence so that expected output is printed....
- 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
Re: could this happen.. ??
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:
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

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

ankurgutpa- Posts: 44
Join date: 2008-08-10
Age: 22
Location: Tandon 72
Permissions of this forum:
You cannot reply to topics in this forum





