rapide has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: it seems that my problem is when the process creating is used in a library so that both the Core application is using it and the 'second application' is using it.
Core:
Application:use Library; $| = 1; Library::createProcess('second application');
Library:use Library; select((select(STDOUT), $|=1)[0]); print STDOUT "Out \n"; print STDERR " -> Err \n"; print STDOUT "Out \n"; print STDERR " -> Err \n"; print STDOUT "Out \n"; print STDERR " -> Err \n"; Library::createProcess('random application');
OUTPUT BECOMES:use IO::Select; use IPC::Open3; sub createProcess($path) { my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $path); my $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); _parseStreams($selector); close(CMD_IN) or die "Unable to close STDIN: $!"; close(CMD_OUT) or die "Unable to close STDOUT: $!"; close(CMD_ERR) or die "Unable to close STDERR: $!"; waitpid($pid, 0) or die "Waitpid failed: $!"; } sub _parseStreams ($) { my($selector) = @_; my(@ready, $fh, $line); while(@ready = $selector->can_read()) { foreach $fh (@ready) { if(fileno($fh) == fileno(CMD_ERR)) { $line = scalar <CMD_ERR>; print STDERR $line; } else { $line = scalar <CMD_OUT>; print STDOUT $line; } $selector->remove($fh) if eof($fh); } } }
Out Out Out -> Err -> Err -> Err
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [UPDATED] How to autoflush streams (i.e. open3 calls)
by BrowserUk (Patriarch) on Jan 29, 2009 at 12:51 UTC | |
|
Re: How to autoflush streams (i.e. open3 calls)
by salva (Canon) on Jan 29, 2009 at 11:21 UTC | |
by rapide (Beadle) on Jan 29, 2009 at 11:24 UTC | |
by salva (Canon) on Jan 29, 2009 at 11:57 UTC | |
by Anonymous Monk on Jan 29, 2009 at 11:25 UTC | |
by rapide (Beadle) on Jan 29, 2009 at 11:29 UTC |