.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" 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 "Wx::Perl::ProcessStream 3pm" .TH Wx::Perl::ProcessStream 3pm "2012-03-28" "perl v5.14.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" Wx::Perl::ProcessStream \- access IO of external processes via events .SH "VERSION" .IX Header "VERSION" Version 0.32 .SH "SYNOPSYS" .IX Header "SYNOPSYS" .Vb 1 \& use Wx::Perl::ProcessStream qw( :everything ); \& \& EVT_WXP_PROCESS_STREAM_STDOUT ( $self, \e&evt_process_stdout ); \& EVT_WXP_PROCESS_STREAM_STDERR ( $self, \e&evt_process_stderr ); \& EVT_WXP_PROCESS_STREAM_EXIT ( $self, \e&evt_process_exit ); \& EVT_WXP_PROCESS_STREAM_MAXLINES ( $self, \e&evt_process_maxlines ); \& \& my $proc1 = Wx::Perl::ProcessStream::Process\->new(\*(Aqperl \-e"print qq($_\en) for(@INC);"\*(Aq, \*(AqMyName1\*(Aq, $self); \& $proc1\->Run; \& \& my $command = \*(Aqexecutable.exe parm1 parm2 parm3\*(Aq \& my $proc2 = Wx::Perl::ProcessStream::Process\->new($command, \*(AqMyName2\*(Aq, $self) \& \->Run; \& \& my @args = qw( executable.exe parm1 parm2 parm3 ); \& my $proc3 = Wx::Perl::ProcessStream::Process\->new(\e@args, \*(AqMyName2\*(Aq, $self); \& $proc3\->Run; \& \& my $proc4 = Wx::Perl::ProcessStream::Process\->new(\e@args, \*(AqMyName2\*(Aq, $self, \*(Aqreadline\*(Aq)\->Run; \& \& my $proc5 = Wx::Perl::ProcessStream::Process\->new(\e@args, \*(AqMyName2\*(Aq, $self); \& \& sub evt_process_stdout { \& my ($self, $event) = @_; \& $event\->Skip(1); \& my $process = $event\->GetProcess; \& my $line = $event\->GetLine; \& \& if($line eq \*(Aqsomething we are waiting for\*(Aq) { \& $process\->WriteProcess(\*(Aqa message to stdin\*(Aq); \& \& $process\->CloseInput() if($finishedwriting); \& } \& ............ \& # To Clear Buffer \& my @buffers = @{ $process\->GetStdOutBuffer }; \& \& } \& \& sub evt_process_stderr { \& my ($self, $event) = @_; \& $event\->Skip(1); \& my $process = $event\->GetProcess; \& my $line = $event\->GetLine; \& print STDERR qq($line\en); \& # To Clear Buffer \& my @errors = @{ $process\->GetStdErrBuffer }; \& } \& \& sub evt_process_exit { \& my ($self, $event) = @_; \& $event\->Skip(1); \& my $process = $event\->GetProcess; \& my $line = $event\->GetLine; \& my @buffers = @{ $process\->GetStdOutBuffer }; \& my @errors = @{ $process\->GetStdErrBuffer }; \& my $exitcode = $process\->GetExitCode; \& ............ \& $process\->Destroy; \& } \& \& sub evt_process_maxlines { \& my ($self, $event) = @_; \& my $process = $event\->GetProcess; \& \& ..... bad process \& \& $process\->Kill; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides the \s-1STDOUT\s0, \s-1STDERR\s0 and exit codes of asynchronously running processes via events. It may be used for long running or blocking processes that provide periodic updates on state via \s-1STDOUT\s0. Simple \s-1IPC\s0 is possible via \s-1STDIN\s0. .PP Do not use this module simply to collect the output of another process. For that, it is much simpler to do: .PP .Vb 1 \& my ($status, $output) = Wx::ExecuteStdout( \*(Aqperl \-e"print qq($_\en) for(@INC);"\*(Aq ); .Ve .SS "Wx::Perl::ProcessStream::Process" .IX Subsection "Wx::Perl::ProcessStream::Process" \fIMethods\fR .IX Subsection "Methods" .IP "new" 12 .IX Item "new" Create a new Wx::Perl::ProcessStream::Process object. You must then use the Run method to execute your command. .Sp .Vb 1 \& my $process = Wx::Perl::ProcessStream::Process\->new($command, $name, $eventhandler, $readmethod); \& \& $command = command text (and parameters) you wish to run. You may also pass a \& reference to an array containing the command and parameters. \& $name = an arbitray name for the process. \& $eventhandler = the Wx EventHandler (Wx:Window) that will handle events for this process. \& $readmethod = \*(Aqread\*(Aq or \*(Aqreadline\*(Aq (default = \*(Aqreadline\*(Aq) an optional param. From Wx version \& 0.75 you can specify the method you wish to use to read the output of an \& external process. \& The default depends on your Wx version ( \*(Aqgetc\*(Aq < 0.75,\*(Aqreadline\*(Aq >= 0.75) \& read \-\- uses the Wx::InputStream\->READ method to read bytes. \& readline \-\- uses the Wx::InputStream\->READLINE method to read bytes \& getc \-\- alias for read (getc not actually used) .Ve .IP "SetMaxLines" 12 .IX Item "SetMaxLines" Set the maximum number of lines that will be read from a continuous stream before raising a \&\s-1EVT_WXP_PROCESS_STREAM_MAXLINES\s0 event. The default is 1000. A continuous stream will cause your application to hang. .Sp .Vb 1 \& $process\->SetMaxLines(10); .Ve .IP "Run" 12 .IX Item "Run" Run the process with the parameters passed to new. On success, returns the process object itself. This allows you to do: my \f(CW$process\fR = Wx::Perl::ProcessStream\->new($command, \f(CW$name\fR, \f(CW$self\fR)\->Run; Returns undef if the process could not be started. .Sp .Vb 2 \& my $process = Wx::Perl::ProcessStream::Process\->new($command, $name, $eventhandler, $readmethod); \& $process\->Run; .Ve .IP "CloseInput" 12 .IX Item "CloseInput" Close the \s-1STDIN\s0 stream of the external process. (Some processes may not close until \s-1STDIN\s0 is closed.) .Sp .Vb 1 \& $process\->CloseInput(); .Ve .IP "GetAppCloseAction" 12 .IX Item "GetAppCloseAction" Returns the current process signal that will used on application exit. Either wxpSIGTERM or wxpSIGKILL. See SetAppCloseAction. .Sp .Vb 1 \& my $action = $process\->GetAppCloseAction(); .Ve .IP "GetExitCode" 12 .IX Item "GetExitCode" Returns the process exit code. It is undefined until a wxpEVT_PROCESS_STREAM_EXIT event has been received. .Sp .Vb 1 \& my $exitcode = $process\->GetExitCode(); .Ve .IP "GetProcessName" 12 .IX Item "GetProcessName" Returns the process name as passed to the OpenProcess constructor. .Sp .Vb 1 \& my $processname = $process\->GetProcessName(); .Ve .IP "GetStdErrBuffer" 12 .IX Item "GetStdErrBuffer" This returns a reference to an array containing all the lines sent by the process to stderr. Calling this clears the process object internal stderr buffer. (This has no effect on the actual process I/O buffers.) .Sp .Vb 1 \& my $arryref = $process\->GetStdErrBuffer(); .Ve .IP "GetStdOutBuffer" 12 .IX Item "GetStdOutBuffer" This returns a reference to an array containing all the lines sent by the process to stdout. Calling this clears the process object internal stdout buffer. (This has no effect on the actual process I/O buffers.) .Sp .Vb 1 \& my $arryref = $process\->GetStdOutBuffer(); .Ve .IP "GetStdErrBufferLineCount" 12 .IX Item "GetStdErrBufferLineCount" This returns the number of lines currently in the stderr buffer. .Sp .Vb 1 \& my $count = $process\->GetStdErrBufferLineCount(); .Ve .IP "GetStdOutBufferLineCount" 12 .IX Item "GetStdOutBufferLineCount" This returns the number of lines currently in the stdout buffer. .Sp .Vb 1 \& my $count = $process\->GetStdOutBufferLineCount(); .Ve .IP "PeekStdErrBuffer" 12 .IX Item "PeekStdErrBuffer" This returns a reference to an array containing all the lines sent by the process to stderr. To retrieve the buffer and clear it, call GetStdErrBuffer instead. .Sp .Vb 1 \& my $arryref = $process\->PeekStdErrBuffer(); .Ve .IP "PeekStdOutBuffer" 12 .IX Item "PeekStdOutBuffer" This returns a reference to an array containing all the lines sent by the process to stdout. To retrieve the buffer and clear it, call GetStdOutBuffer instead. .Sp .Vb 1 \& my $arryref = $process\->PeekStdOutBuffer(); .Ve .IP "GetProcessId" 12 .IX Item "GetProcessId" Returns the process id assigned by the system. .Sp .Vb 1 \& my $processid = $process\->GetProcessId(); .Ve .IP "GetPid" 12 .IX Item "GetPid" Returns the process id assigned by the system. .Sp .Vb 1 \& my $processid = $process\->GetPid(); .Ve .IP "IsAlive" 12 .IX Item "IsAlive" Check if the process still exists in the system. Returns 1 if process exists, 0 if process does not exist. If the process has already signalled its exit, the IsAlive method will always return 0. Therefore IsAlive should always return 0 (false) once a \s-1EVT_WXP_PROCESS_STREAM_EXIT\s0 event has been sent. .Sp .Vb 1 \& my $isalive = $process\->IsAlive(); .Ve .IP "KillProcess" 12 .IX Item "KillProcess" Send a \s-1SIGKILL\s0 signal to the external process. .Sp .Vb 1 \& $process\->KillProcess(); .Ve .IP "SetAppCloseAction" 12 .IX Item "SetAppCloseAction" When your application exits, any remaining Wx::Perl::ProcessStream::Process objects will be signaled to close. The default signal is wxpSIGTERM but you can change this to wxpSIGKILL if you are sure this is what you want. .Sp .Vb 1 \& $process\->SetAppCloseAction( $newaction ); \& \& $newaction = one of wxpSIGTERM, wxpSIGKILL .Ve .IP "TerminateProcess" 12 .IX Item "TerminateProcess" Send a \s-1SIGTERM\s0 signal to the external process. .Sp .Vb 1 \& $process\->TerminateProcess(); .Ve .IP "WriteProcess" 12 .IX Item "WriteProcess" Write to the \s-1STDIN\s0 of process. .Sp .Vb 1 \& $process\->WriteProcess( $writedata . "\en" ); \& \& $writedata = The data you wish to write. Remember to add any appropriate line endings your external process may expect. .Ve .SS "Wx::Perl::ProcessStream" .IX Subsection "Wx::Perl::ProcessStream" \fIMethods\fR .IX Subsection "Methods" .IP "OpenProcess" 12 .IX Item "OpenProcess" Run an external process. \s-1DEPRECATED\s0 \- use Wx::Perl::ProcessStream::Process\->\fInew()\fR\->Run; If the process is launched successfully, returns a Wx::Perl::ProcessStream::Process object. If the process could not be launched, returns undef; .Sp .Vb 1 \& my $process = Wx::Perl::ProcessStream\->OpenProcess($command, $name, $eventhandler, $readmethod); \& \& $command = command text (and parameters) you wish to run. You may also pass a \& reference to an array containing the command and parameters. \& $name = an arbitray name for the process. \& $eventhandler = the Wx object that will handle events for this process. \& $process = Wx::Perl::ProcessStream::Process object \& $readmethod = \*(Aqgetc\*(Aq or \*(Aqreadline\*(Aq (default = \*(Aqreadline\*(Aq) an optional param. From Wx version \& 0.75 you can specifiy the method you wish to use to read the output of an \& external process. The default depends on your Wx version ( \*(Aqgetc\*(Aq < 0.75, \& \*(Aqreadline\*(Aq >= 0.75) \& \*(Aqgetc\*(Aq uses the Wx::InputStream\->GetC method to read bytes. \& \*(Aqreadline\*(Aq, uses the wxPerl implementation of Wx::InputStream\->READLINE. .Ve .Sp If the process could not be started then zero is returned. You should destroy each process after it has completed. You can do this after receiving the exit event. .IP "GetDefaultAppCloseAction" 12 .IX Item "GetDefaultAppCloseAction" Returns the default on application close action that will be given to new processes. When your application exits, any remaining Wx::Perl::ProcessStream::Process objects will be signalled to close. The default signal is wxpSIGTERM but you can change this to wxpSIGKILL if you are sure this is what you want. Whenever a mew process is opened, it is given the application close action returned by GetDefaultAppCloseAction. You can also set the application close action at an individual process level. .Sp .Vb 1 \& my $def\-action = Wx::Perl::ProcessStream\->SetDefaultAppCloseAction(); \& \& $def\-action will be one of wxpSIGTERM or wxpSIGKILL; (default wxpSIGTERM) .Ve .IP "SetDefaultAppCloseAction" 12 .IX Item "SetDefaultAppCloseAction" Sets the default on application close action that will be given to new processes. See GetDefaultAppCloseAction. .Sp .Vb 1 \& Wx::Perl::ProcessStream\->SetDefaultAppCloseAction( $newdefaction ); \& \& $newdefaction = one of wxpSIGTERM or wxpSIGKILL .Ve .IP "SetDefaultMaxLines" 12 .IX Item "SetDefaultMaxLines" Sets the default maximum number of lines that will be processed continuously from an individual process. If a process produces a continuous stream of output, this would hang your application. This setting provides a maximum number of lines that will be read from the process streams before control is yielded and the events can be processed. Additionally, a \s-1EVT_WXP_PROCESS_STREAM_MAXLINES\s0 event will be sent to the eventhandler. The setting can also be set on an individual process basis using \f(CW$process\fR\->SetMaxLines .Sp .Vb 1 \& Wx::Perl::ProcessStream\->SetDefaultMaxLines( $maxlines ); \& \& the default maxlines number is 1000 .Ve .IP "GetPollInterval" 12 .IX Item "GetPollInterval" Get the current polling interval. See SetPollInterval. .Sp .Vb 1 \& $milliseconds = Wx::Perl::ProcessStream\->GetPollInterval(); .Ve .IP "SetPollInterval" 12 .IX Item "SetPollInterval" When all buffers are empty but there are still running external process, the module will pause before polling the processes again for output. By default, the module waits for 500 milliseconds. You can set the value of this polling intrval with this method. Internally, a Wx::Timer object is used to handle polling and the value you set here is passed directly to that. The precision of the intervals is \s-1OS\s0 dependent. .Sp .Vb 1 \& Wx::Perl::ProcessStream\->SetPollInterval( $milliseconds ); \& \& $milliseconds = number of milliseconds to wait when no buffer activity .Ve .SS "Wx::Perl::ProcessStream::ProcessEvent" .IX Subsection "Wx::Perl::ProcessStream::ProcessEvent" A Wx::Perl::ProcessStream::ProcessEvent is sent whenever an external process started with OpenProcess writes to \s-1STDOUT\s0, \s-1STDERR\s0 or when the process exits. .PP \fIEvent Connectors\fR .IX Subsection "Event Connectors" .IP "\s-1EVT_WXP_PROCESS_STREAM_STDOUT\s0" 12 .IX Item "EVT_WXP_PROCESS_STREAM_STDOUT" Install an event handler for an event of type wxpEVT_PROCESS_STREAM_STDOUT exported on request by this module. The event subroutine will receive a Wx::Perl::ProcessStream::ProcessEvent for every line written to \s-1STDOUT\s0 by the external process. .Sp .Vb 1 \& EVT_WXP_PROCESS_STREAM_STDOUT( $eventhandler, $codref ); .Ve .IP "\s-1EVT_WXP_PROCESS_STREAM_STDERR\s0" 12 .IX Item "EVT_WXP_PROCESS_STREAM_STDERR" Install an event handler for an event of type wxpEVT_PROCESS_STREAM_STDERR exported on request by this module. The event subroutine will receive a Wx::Perl::ProcessStream::ProcessEvent for every line written to \s-1STDERR\s0 by the external process. .Sp .Vb 1 \& EVT_WXP_PROCESS_STREAM_STDERR( $eventhandler, $codref ); .Ve .IP "\s-1EVT_WXP_PROCESS_STREAM_EXIT\s0" 12 .IX Item "EVT_WXP_PROCESS_STREAM_EXIT" Install an event handler for an event of type wxpEVT_PROCESS_STREAM_EXIT exported on request by this module. The event subroutine will receive a Wx::Perl::ProcessStream::ProcessEvent when the external process exits. .Sp .Vb 1 \& EVT_WXP_PROCESS_STREAM_EXIT( $eventhandler, $codref ); .Ve .IP "\s-1EVT_WXP_PROCESS_STREAM_MAXLINES\s0" 12 .IX Item "EVT_WXP_PROCESS_STREAM_MAXLINES" Install an event handler for an event of type wxpEVT_PROCESS_STREAM_MAXLINES exported on request by this module. The event subroutine will receive a Wx::Perl::ProcessStream::ProcessEvent when the external process produces a continuous stream of lines on stderr and stdout that exceed the max lines set via \f(CW$process\fR\->SetMaxLines or Wx::Perl::ProcessStream\->SetDefaultMaxLines. .Sp .Vb 1 \& EVT_WXP_PROCESS_STREAM_MAXLINES( $eventhandler, $codref ); .Ve .PP \fIMethods\fR .IX Subsection "Methods" .IP "GetLine" 12 .IX Item "GetLine" For events of type wxpEVT_PROCESS_STREAM_STDOUT and wxpEVT_PROCESS_STREAM_STDERR this will return the line written by the process. .IP "GetProcess" 12 .IX Item "GetProcess" This returns the process that raised the event. If this is a wxpEVT_PROCESS_STREAM_EXIT event you should destroy the process with \f(CW$process\fR\->Destroy; .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright (C) 2007\-2010 Mark Dootson, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to Johan Vromans for testing and suggesting a better interface. .SH "AUTHOR" .IX Header "AUTHOR" Mark Dootson, \f(CW\*(C`\*(C'\fR .SH "SEE ALSO" .IX Header "SEE ALSO" The distribution includes examples in the 'example' folder. From the source root, run .PP .Vb 1 \& perl \-Ilib example/psexample.pl .Ve .PP You can enter commands, execute them and view results. .PP You may also wish to consult the wxWidgets manuals for: .PP Wx::Process .PP Wx::Execute .PP Wx::ExecuteArgs .PP Wx::ExecuteCommand .PP Wx::ExecuteStdout .PP Wx::ExecuteStdoutStderr