Re: Strange Windows warning with IO.popen: The process tried to write to a nonexistent pipe



On Feb 19, 11:56 pm, Daniel Berger <djber...@xxxxxxxxx> wrote:
Luis Lavena wrote:
On Feb 19, 8:02 pm, Daniel Berger <djber...@xxxxxxxxx> wrote:
Hi all,

Ruby 1.8.6
Windows XP Pro

I tried this standalone snippet:

io = IO.popen('date /t')

Running that with -w I get this warning:

The process tried to write to a nonexistent pipe

I got the same without the -w option.

This is related to the redirection of stdio and stdout and the
premature termination of them (in the child process spawn by ruby).

If you add a Kernel.gets() or anything that delays the script
termiantion you wouldn't get the warning.

So, how do we fix it Luis?


To be more exact, the error message is not coming from ruby itself,
but is the output genereated by STDERR from the child process being
captured by the console you're running.

This is a small example, doing the same thing with FreeBASIC:

open pipe "date /t" for input as #1

(compile with fbc.exe) and the output will be:

D:\Users\Luis\Desktop>u
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.

The same problem shows when you try to use "echo" and pipes in batch
files from time to time, there is no guarantee that the pipe will
exist at that time, and ruby is closing itself before the child
process can actually execute.

Adding a sleep also prevent from getting the warning, but this seems
to have been raised in every language or scripting processor (VBScript
and PowerShell) too.

What are you trying to do? if you're just ignoring the output of the
'date /t', why don't you use backtick syntax?

io = `date /t`

Using that syntax worked all the time, (from 10 runs, I got 0 error
messages).

Regards,
--
Luis Lavena
.



Relevant Pages

  • Re: How to time out a forked command but still see output?
    ... Again, if the program hangs and there's a timeout, then the handler ... closes the pipe and launchs the program in the ... be aware the child process will ... terminate with a SIGPIPE as soon as it tries to write to the closed ...
    (comp.lang.perl.misc)
  • Re: Pipes on Wince (I have them), and device auto-loading.
    ... appropriate paths for each child process. ... the device nature of the pipe from the user, ... like to somehow have the device auto deactivate when the last ... In PipeLib there is a thread that waits ...
    (microsoft.public.windowsce.embedded)
  • Re: Parent process unable to read messages from child process
    ... exactly as you've posted here, However, the parent process populates ... the @detail array with only one pipe output. ... If the amount of output of each child process is small, ... close $uncompwrite; ...
    (comp.lang.perl.misc)
  • Re: does IO.read block?
    ... concurrency right: you need to make sure that stderr and stdout are ... on one of them fills up your child process is blocked. ... exception to chuck down the pipe. ... altered or corrupted during transmission. ...
    (comp.lang.ruby)
  • Problem in Interprocess Communication using anonymous pipes, when
    ... I am providing the codes for Parent and Child processes. ... // Creates two anonymous pipes to the STDIN and STDOUT of the child process ... which is connected to parent process using an anonymous pipe. ... GetCurrentProcess, &hChildStdoutRdDup, 0, ...
    (microsoft.public.vc.language)