rapide has asked for the wisdom of the Perl Monks concerning the following question:
The executed application
The print application#!/usr/bin/perl use Process; $| = 1; print STDERR "Started ..!\n"; Process::createProcess('./printApplication'); print STDERR ".. Finished!\n";
The library that contains execute functionality#!/usr/bin/perl print STDERR " printing some text\n"; print STDERR " printing some text\n"; print STDERR " printing some text\n"; print STDERR " printing some text\n"; sleep 10;
UPDATE: I want the main application to print out the output from the second application immediately.package Process; use strict; use warnings; use IO::Select; use IPC::Open3; sub createProcess ($) { my($path) = @_; my($selector, $pid, @ready, $fh, $line); $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $path); $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); while(@ready = $selector->can_read()) { foreach $fh (@ready) { if(fileno($fh) == fileno(CMD_ERR)) { $line = scalar <CMD_ERR>; if(defined $line) { print STDERR $line; } } else { $line = scalar <CMD_OUT>; if(defined $line) { print STDOUT $line; } } $selector->remove($fh) if eof($fh); } } waitpid($pid, 0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Autoflush not possible when sleep is used?
by almut (Canon) on Feb 06, 2009 at 10:29 UTC | |
by moritz (Cardinal) on Feb 06, 2009 at 10:31 UTC | |
by almut (Canon) on Feb 06, 2009 at 10:38 UTC | |
by rapide (Beadle) on Feb 06, 2009 at 16:12 UTC | |
|
Re: Autoflush not possible when sleep is used?
by JavaFan (Canon) on Feb 06, 2009 at 10:20 UTC |