-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code in IPC::Open3 doc doesn't work #22608
Comments
Working version: open local *OUTFILE, '>>', 'output.txt' or die "open failed: $!";
my $pid = open3('<&STDIN', '>&OUTFILE', undef, "printf", "foo\\n"); |
Bug first reported on StackOverflow |
'>&' . fileno $outfile ... should do the job without needing the bareword handle |
These docs were changed in ef395fa. The previous version didn't include any examples of doing this. |
I am always suspicious of "there's a bug in perl", "the other way is ugly" and "i'll do it myself" comments At the first glance this comment is checking all the boxes:
|
I don't know if the bug has been fixed, but that has not always been the case. It appears to work, but--IIRC--a close fails, which can cause issues--EOF never reached?--in some situations. I allude to this problem in this post from 2012:
|
As you should be. But rather than making such a comment, you should have tested it like I did.
I've answered "hundreds" of questions about The documentation doesn't reflect the behaviour of the module (past or present). |
@ikegami Sorry I wasn't clear, I was talking about the comment I quoted (from IPC::Open3), not the reproducibility of your issue. I did run the example you gave (from the docs) and it did the thing you said it would (leaving the file untouched) so I didn't have much to add on that topic (especially when I only tested it on BSD with 5.20.2 and your issue talked about windows too) |
Unfortunately, this feature is based on parsing out filehandle names from strings, so it requires bareword filehandles to work. Try to make this clearer in the documentation and mention that arguments starting with `>&` or `<&` are input parameters (i.e. existing open handles to use) as opposed to regular output parameters (which open3 connects to newly created pipes). Fixes Perl#22608.
Unfortunately, this feature is based on parsing out filehandle names from strings, so it requires bareword filehandles to work. Try to make this clearer in the documentation and mention that arguments starting with `>&` or `<&` are input parameters (i.e. existing open handles to use) as opposed to regular output parameters (which open3 connects to newly created pipes). Fixes #22608.
Where
IPC::Open3
Description
The synopsis contains this code. It doesn't work. No output ends up in
output.txt
.Passing a lexical variable containing a file handle to
open3
has never worked. At least not on non-Windows systems. Never tried it on a Windows system which uses a very different implementation.The text was updated successfully, but these errors were encountered: