Solved

windows command line pipe "|" not working as expected

Posted on 2008-06-13
4
4,522 Views
Last Modified: 2013-11-14
> 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?
0
Comment
Question by:ineya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:fcarrai
ID: 21787725
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".
0
 
LVL 3

Author Comment

by:ineya
ID: 21787740
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".
0
 
LVL 3

Assisted Solution

by:fcarrai
fcarrai earned 500 total points
ID: 21787875
In my opinion the reason(s) has to be searched in the pipe implementation mechanisms and in the stdin, stdout redirection. The "mix" you are referring to could be possible only  if the application has independent threads for input and output. This doesn't look to be your case.


0
 
LVL 3

Accepted Solution

by:
ineya earned 0 total points
ID: 21788023
Problem appears to be in windows port of netcat made by Chris Wysopal (also known as Weld Pond).
I tried to get source codes, but they are nowhere to be found, so I can just guess.

I wrote a small utility just to simulate output coming from network
time | my_utility
and it has no problem at all to write to output.

So I tried cygwin netcat and it also works very well. So my guess is there is some limitation (or bug) in windows port.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question