unxutils: 'yes| tail -5' hangs.

  • Thread starter Thread starter silly
  • Start date Start date
S

silly

unxutils: 'yes| tail -5' hangs.

Hello, when I enter the above command I get:-
yes | head -5
y
y
y
y
y


and it just hangs there.

If its 'head' then any ideas on where to get a 'head' command that works
like
the *nix one?

Thanks

Hal.
 
silly said:
unxutils: 'yes| tail -5' hangs.

Hello, when I enter the above command I get:-



y
y
y
y
y


and it just hangs there.

Hi,

It's still waiting for end-of-file. Press Ctrl+Z then Enter to indicate
end-of-file.
 
Bill said:
That's true :-), but it will produce the same behavior, because a
program that reads standard input will still wait for end-of-file before
the pipe is closed.

Not knowing yes before, I didn't interpret "silly's" command as valid.

You're right in that it doesn't matter which program waits for eof.
 
Thanks guys,

This seems to suggest that using 'head' in a pipe is practically useless for
large files (assuming its used in a batch file). Pity really.

Hal.
 
silly wrote:
Please don't top post.
This seems to suggest that using 'head' in a pipe is practically useless for
large files (assuming its used in a batch file). Pity really.

LOL, that is a "silly"-conclusion ;-). Yes steadily outputs y crlf.
Due to the fact that a second command processor receives this stream,
nothing will show up until the stream is terminated from outside.

BTW it's difficult to decide if it are really the first 5 five lines
with y crlf.

No offense meant it's just your pseudonym ;-)
 
Matthias Tacke" said:
Please don't top post.
Fair enough, this time I'll oblige.
LOL, that is a "silly"-conclusion ;-). Yes steadily outputs y crlf.
Yes I know what 'yes' does. It was you who didn't ;o)
Due to the fact that a second command processor receives this stream,
nothing will show up until the stream is terminated from outside.

It was a silly conclusion, mainly because I didn't experiment a bit more. On
winxp (at home now!), when you enter 'dir /s c:\ | head -10' it works
exactly as expected, 'type largefile | head -10' works as expected - except
for the extra line: 'The process tried to write to a nonexistent pipe.'
Presumably this means that head finished before the type command which
checked to see if it was writing to a pipe. Perhaps the DIR command checked
also but didn't think it worth mentioning a non-existing pipe.

If I have a file 'a.bat' with:
@echo off
echo a
echo a'
....
echo a

Then try 'a | head -5' (on winxp), I get:-
a
a
a
a
a
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.

I know *nix pipes are somewhat different from windows ones but I dont know
the details. Seems to me that to make the 'yes' command to work like it does
on linux, 'yes' needs some pipe checking logic? Or is this silly?

Do all windows commands have pipe checking code?
 
silly said:
It was a silly conclusion, mainly because I didn't experiment a bit more. On
winxp (at home now!), when you enter 'dir /s c:\ | head -10' it works
exactly as expected, 'type largefile | head -10' works as expected - except
for the extra line: 'The process tried to write to a nonexistent pipe.'
Presumably this means that head finished before the type command which
checked to see if it was writing to a pipe. Perhaps the DIR command checked
also but didn't think it worth mentioning a non-existing pipe.
IMO its a timing thing. Opposing to my idea with yes, head seems to
terminate after a distinct time/amount of data received.

To avoid the error message redirect error output to nul.

type largefile 2>NUL | head -10

I dont' know your head version - some have a file option.
But this reminds me of the useless use of cat award ;-) Why not use:

head -10 <largefile

The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.

I know *nix pipes are somewhat different from windows ones but I dont know
the details. Seems to me that to make the 'yes' command to work like it does
on linux, 'yes' needs some pipe checking logic? Or is this silly?

Do all windows commands have pipe checking code?
Presumably its the shell itself as echo is an internal command to cmd.exe

Since I'm lazy, I tried this and had no problems (w2k and cmd.exe)
with any combination of output lines and the head lines number.

K:\PUBLIC\SYS\TOOLS\WUUP100>(for /l %a in (1 1 5) do @echo %a)|head -10
1
2
3
4
5

K:\PUBLIC\SYS\TOOLS\WUUP100>(for /l %a in (1 1 10) do @echo %a)|head -10
1
2
3
4
5
6
7
8
9
10

K:\PUBLIC\SYS\TOOLS\WUUP100>(for /l %a in (1 1 10) do @echo %a)|head -5
1
2
3
4
5

As you might guess the used head is from the wuup100 package.

HTH
 
Matthias said:
I dont' know your head version - some have a file option.
But this reminds me of the useless use of cat award ;-) Why not use:

head -10 <largefile

Indeed...I was just wondering the same thing. :-)

As a side note, my linex.exe reads the entire file into memory first, so
it may not be suitable for the OP's application.
 
Back
Top