Farabi

 view release on metacpan or  search on metacpan

eg/run_system_cmd.pl  view on Meta::CPAN

						}
						else {
							$error .= $bytes;
						}

						$results{$pid} = {
							pid    => $pid,
							cmd    => join( ' ', @cmds ),
							stdout => $output,
							stderr => $error,
							status => 'running',
							exit   => 0,
						};

					}
				);
				$stream->on(
					close => sub {
						my $stream = shift;
						say "close $handle!";
					}
				);
				$stream->on(
					error => sub {
						my ( $stream, $err ) = @_;
						say "error at $handle!";
					}
				);

			}

		  }

	);

	my $interval;
	$interval = Mojo::IOLoop->recurring(
		1 => sub {
			my $loop = shift;

			return unless defined $cmd;

			if ( $cmd->is_terminated ) {

				# the handles are not closed yet
				# but $cmd->exit() et al. are available
				say "process " . $cmd->pid . " has terminated";

				my $pid = $cmd->pid;
				$results{$pid}->{status} = 'stopped';
				$results{$pid}->{exit} = $cmd->exit;

				# done
				$cmd->close;

				# Stop the process watchdog
				$loop->remove($interval);

			}
			else {
				say "Still alive!";
			}
		}
	);

	$self->render( text => <<HTML);
Process has been started. 
<p>
Please click <a href="/">here</a> to return to the previous form.|
</p>
HTML
};

app->start;



( run in 0.916 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )