.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Arch::Run 3pm" .TH Arch::Run 3pm "2005-10-08" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Arch::Run \- run subprocesses and capture output .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Gtk2 \-init; \& use Arch::Run qw(poll run_async LINES); \& \& my $window = Gtk2::Window\->new; \& my $label = Gtk2::Label\->new; \& my $pbar = Gtk2::ProgressBar\->new; \& my $vbox = Gtk2::VBox\->new; \& $vbox\->add($label); $vbox\->add($pbar); $window\->add($vbox); \& $window\->signal_connect(destroy => sub { Gtk2\->main_quit; }); \& $window\->set_default_size(200, 48); $window\->show_all; \& sub set_str { $label\->set_text($_[0]); } \& \& my $go = 1; # keep progress bar pulsing \& Glib::Timeout\->add(100, sub { $pbar\->pulse; poll(0); $go; }); \& \& run_async( \& command => [ \*(Aqdu\*(Aq, \*(Aq\-hs\*(Aq, glob(\*(Aq/usr/share/*\*(Aq) ], \& mode => LINES, \& datacb => sub { chomp(my $str = $_[0]); set_str($str); }, \& exitcb => sub { $go = 0; set_str("exit code: $_[0]"); }, \& ); \& \& Gtk2\->main; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Arch::Run allows the user to run run subprocesses and capture their output in a single threaded environment without blocking the whole application. .PP You can use either \fBpoll\fR to wait for and handle process output, or use \fBhandle_output\fR and \fBhandle_exits\fR to integrate \&\fBArch::Run\fR with your applications main loop. .SH "METHODS" .IX Header "METHODS" The following functions are available: \&\fBrun_with_pipe\fR, \&\fBrun_async\fR, \&\fBget_output_handle\fR, \&\fBhandle_output\fR, \&\fBpoll\fR, \&\fBwait\fR, \&\fBkillall\fR, \&\fBobserve\fR, \&\fBunobserve\fR. .ie n .IP "\fBrun_with_pipe\fR \fI\fI$command\fI\fR" 4 .el .IP "\fBrun_with_pipe\fR \fI\f(CI$command\fI\fR" 4 .IX Item "run_with_pipe $command" .PD 0 .ie n .IP "\fBrun_with_pipe\fR \fI\fI$executable\fI\fR \fI\fI$argument\fI\fR ..." 4 .el .IP "\fBrun_with_pipe\fR \fI\f(CI$executable\fI\fR \fI\f(CI$argument\fI\fR ..." 4 .IX Item "run_with_pipe $executable $argument ..." .PD Fork and exec a program with \s-1STDIN\s0 and \s-1STDOUT\s0 connected to pipes. In scalar context returns the output handle, \s-1STDIN\s0 will be connected to /dev/null. In list context, returns the output and input handle. .Sp The programs standard error handle (\s-1STDERR\s0) is left unchanged. .ie n .IP "\fBrun_async\fR \fI\fI%args\fI\fR" 4 .el .IP "\fBrun_async\fR \fI\f(CI%args\fI\fR" 4 .IX Item "run_async %args" Run a command asyncronously in the background. Returns the subprocesses pid. .Sp Valid keys for \fI\f(CI%args\fI\fR are: .RS 4 .ie n .IP "\fBcommand\fR => \fI\fI$command\fI\fR" 4 .el .IP "\fBcommand\fR => \fI\f(CI$command\fI\fR" 4 .IX Item "command => $command" .PD 0 .ie n .IP "\fBcommand\fR => [ \fI\fI$executable\fI\fR \fI\fI$argument\fI\fR ... ]" 4 .el .IP "\fBcommand\fR => [ \fI\f(CI$executable\fI\fR \fI\f(CI$argument\fI\fR ... ]" 4 .IX Item "command => [ $executable $argument ... ]" .PD Program and parameters. .ie n .IP "\fBmode\fR => \fI\fI$accum_mode\fI\fR" 4 .el .IP "\fBmode\fR => \fI\f(CI$accum_mode\fI\fR" 4 .IX Item "mode => $accum_mode" Control how output data is accumulated and passed to \fBdata\fR and \&\fBfinish\fR callbacks. .Sp \&\fI\f(CI$accum_mode\fI\fR can be one of .RS 4 .IP "\fB\s-1RAW\s0\fR" 4 .IX Item "RAW" No accumulation. Pass output to \fBdata\fR callback as it is received. .IP "\fB\s-1LINES\s0\fR" 4 .IX Item "LINES" Accumulate output in lines. Pass every line separately to \fBdata\fR callback. .IP "\fB\s-1ALL\s0\fR" 4 .IX Item "ALL" Accumulate all data. Pass complete command output as one block to \&\fBdata\fR callback. .RE .RS 4 .RE .ie n .IP "\fBdatacb\fR => \fI\fI$data_callback\fI\fR" 4 .el .IP "\fBdatacb\fR => \fI\f(CI$data_callback\fI\fR" 4 .IX Item "datacb => $data_callback" Codeblock or subroutine to be called when new output is available. Receives one parameter, the accumulated command output. .ie n .IP "\fBexitcb\fR => \fI\fI$exit_callback\fI\fR" 4 .el .IP "\fBexitcb\fR => \fI\f(CI$exit_callback\fI\fR" 4 .IX Item "exitcb => $exit_callback" Codeblock or subroutine to be called when subprocess exits. Receives a single parameter, the commands exit code. (Or maybe not. We have to handle SIG{\s-1CHLD\s0} then. But maybe we have to do so anyway.) .RE .RS 4 .RE .ie n .IP "\fBget_output_handle\fR \fI\fI$pid\fI\fR" 4 .el .IP "\fBget_output_handle\fR \fI\f(CI$pid\fI\fR" 4 .IX Item "get_output_handle $pid" Returns the \s-1STDOUT\s0 handle of process \f(CW$pid\fR. You should never directly read from the returned handle. Use IO::Select or IO::Poll to wait for output and call \fBhandle_output\fR to process the output. .ie n .IP "\fBhandle_output\fR \fI\fI$pid\fI\fR" 4 .el .IP "\fBhandle_output\fR \fI\f(CI$pid\fI\fR" 4 .IX Item "handle_output $pid" Handle available output from process \fI\f(CI$pid\fI\fR. .Sp \&\fB\s-1ATTENTION:\s0\fR Call this method only if there really is output to be read. It will block otherwise. .ie n .IP "\fBpoll\fR \fI\fI$timeout\fI\fR" 4 .el .IP "\fBpoll\fR \fI\f(CI$timeout\fI\fR" 4 .IX Item "poll $timeout" Check running subprocesses for available output and run callbacks as appropriate. Wait at most \fI\f(CI$timeout\fI\fR seconds when no output is available. .Sp Returns the number of processes that had output available. .ie n .IP "\fBwait\fR \fI\fI$pid\fI\fR" 4 .el .IP "\fBwait\fR \fI\f(CI$pid\fI\fR" 4 .IX Item "wait $pid" Wait for subprocess \fI\f(CI$pid\fI\fR to terminate, repeatedly calling \fBpoll\fR. Returns the processes exit status or \f(CW\*(C`undef\*(C'\fR if \fBpoll\fR has already been called after the processes exit. .ie n .IP "\fBkillall\fR [\fI\fI$signal\fI\fR]" 4 .el .IP "\fBkillall\fR [\fI\f(CI$signal\fI\fR]" 4 .IX Item "killall [$signal]" Send signal \fI\f(CI$signal\fI\fR (\fB\s-1SIGINT\s0\fR if omitted) to all managed subprocesses, and wait until every subprocess to terminate. .ie n .IP "\fBobserve\fR \fI\fI$observer\fI\fR" 4 .el .IP "\fBobserve\fR \fI\f(CI$observer\fI\fR" 4 .IX Item "observe $observer" Register an observer object that wishes to be notified of running subprocesses. \fI\f(CI$observer\fI\fR should implement one or more of the following methods, depending on which event it wishes to receive. .RS 4 .ie n .IP "\fB\->cmd_start\fR \fI\fI$pid\fI\fR \fI\fI$executable\fI\fR \fI\fI$argument\fI\fR ..." 4 .el .IP "\fB\->cmd_start\fR \fI\f(CI$pid\fI\fR \fI\f(CI$executable\fI\fR \fI\f(CI$argument\fI\fR ..." 4 .IX Item "->cmd_start $pid $executable $argument ..." Called whenever a new subprocess has been started. Receives the subprocesses \s-1PID\s0 and the executed command line. .ie n .IP "\fB\->cmd_output_raw\fR \fI\fI$pid\fI\fR \fI\fI$data\fI\fR" 4 .el .IP "\fB\->cmd_output_raw\fR \fI\f(CI$pid\fI\fR \fI\f(CI$data\fI\fR" 4 .IX Item "->cmd_output_raw $pid $data" Called whenever a subprocess has generated output. Receives the subprocesses \s-1PID\s0 and a block of output data. .Sp \&\fB\s-1NOTE:\s0\fR \fI\f(CI$data\fI\fR is not preprocesses (e.g. split into lines). \&\fBcmd_output_raw\fR receives data block as if \fB\s-1RAW\s0\fR mode was used. .ie n .IP "\fB\->cmd_exit\fR \fI\fI$pid\fI\fR \fI\fI$exitcode\fI\fR" 4 .el .IP "\fB\->cmd_exit\fR \fI\f(CI$pid\fI\fR \fI\f(CI$exitcode\fI\fR" 4 .IX Item "->cmd_exit $pid $exitcode" Called whenever a subprocess exits. Receives the subprocesses \s-1PID\s0 and exit code. .RE .RS 4 .RE .ie n .IP "\fBunobserve\fR \fI\fI$observer\fI\fR" 4 .el .IP "\fBunobserve\fR \fI\f(CI$observer\fI\fR" 4 .IX Item "unobserve $observer" Remove \fI\f(CI$observer\fI\fR from observer list.