Link to home
Start Free TrialLog in
Avatar of ineya
ineyaFlag for Czechia

asked on

windows command line pipe "|" not working as expected

> I have 2 shell windows open (cmd.exe), in one I run netcat as server and in other one netcat as client.

shell 1: time | "c:\Program Files\netcat\nc.exe" -l -p 22

shell 2: "c:\Program Files\netcat\nc.exe" localhost 22
The current time is: 20:00:25,28
Enter the new time:

> So far, everything looks good.
> Now I enter something in shell 2
shell 2: blahblah

> but nothing is displayed in shell 1
> I enter 123 in shell 1
shell 1: 123

> and suddenly I see:
shell 1: 123
shell 1: blahblah

> the blahblah string was waiting somewhere for something to happen, but I have no clue why. You can also try to send larger string or more strings from shell 2, but these will not appear in shell 1, until some text is sent from shell 1. The almost exact scenario (use "date" instead of "time") works on linux as expected.

> So my question is, why is the input from shell 2 not displayed immediately in shell 1?
Avatar of fcarrai
fcarrai

On shell 1 the "time" command remain waiting for the new time setting.
Could it be this the problem ?
Repeat your test using a nomal "echo 123" command instead of "time".
Avatar of ineya

ASKER

Yes, this looks like cause, but it is not clear to me, why it is affecting output of netcat. It appears as if the netcat doesn't have access to stdout in that moment. And instead of mixing outputs from 'time' (the output produced by echoing your input) and netcat, windows is somehow switching from one to another under some "specific conditions".
SOLUTION
Avatar of fcarrai
fcarrai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial