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

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

However, if I add a simple “io.read” on the next line the warning goes
away. I do not see the same warning on Unix systems.

What’s the deal?

Thanks,

Dan

On Feb 19, 8:02 pm, Daniel B. [email protected] wrote:

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.

HTH,

Luis L. wrote:

Running that with -w I get this warning:
termiantion you wouldn’t get the warning.
So, how do we fix it Luis?

Regards,

Dan

On Feb 19, 2008, at 6:56 PM, Daniel B. wrote:

So, how do we fix it Luis?

Regards,

Dan

you just need to make sure ruby doesn’t exit before the process is done

at_exit{ Process.kill io.pid}

or

at_exit{ io.read }

etc

a @ http://codeforpeople.com/

Hi,

At Wed, 20 Feb 2008 07:02:31 +0900,
Daniel B. wrote in [ruby-talk:291663]:

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 have deja vu on this question…, the thread from
[ruby-core:14126] can’t help you?

On Feb 19, 11:56 pm, Daniel B. [email protected] wrote:

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,