in reply to open to pipe fails with exit on Windows

Same thing on Unix as well:

What happens is this: perl(2) command exists, thus the open succeeds and perl(2) _is_ running. The failure itself from perl(2) (exiting), the invoking perl(1) setting $?, etc, does happen later, i.e. on the first print (*) on that handle.

The fix of course is doing as romandas suggests.

(*) make that actual use of the underlying handle. So I don't known what happens in case of empty print SORT "". Also it depends on whether the handle does buffering or directly talks to the other process perl(2). Write a small test case and ask your setup how it will behave :).

If the invoked command dies after reading a bit, the error will be visible to perl(1) even later (in case of perl(2), it dies _without_ reading from STDIN of course).

  • Comment on Re: open to pipe fails with exit on Windows