Debian Codegraph @

upstream/opensuse-tumbleweed/man3/IPC::Cmd.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "IPC::Cmd 3pm"
61 .TH IPC::Cmd 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 IPC::Cmd \- finding and running system commands made easy
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use IPC::Cmd qw[can_run run run_forked];
72 \&
73 \& my $full_path = can_run(\*(Aqwget\*(Aq) or warn \*(Aqwget is not installed!\*(Aq;
74 \&
75 \& ### commands can be arrayrefs or strings ###
76 \& my $cmd = "$full_path \-b theregister.co.uk";
77 \& my $cmd = [$full_path, \*(Aq\-b\*(Aq, \*(Aqtheregister.co.uk\*(Aq];
78 \&
79 \& ### in scalar context ###
80 \& my $buffer;
81 \& if( scalar run( command => $cmd,
82 \& verbose => 0,
83 \& buffer => \e$buffer,
84 \& timeout => 20 )
85 \& ) {
86 \& print "fetched webpage successfully: $buffer\en";
87 \& }
88 \&
89 \&
90 \& ### in list context ###
91 \& my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
92 \& run( command => $cmd, verbose => 0 );
93 \&
94 \& if( $success ) {
95 \& print "this is what the command printed:\en";
96 \& print join "", @$full_buf;
97 \& }
98 \&
99 \& ### run_forked example ###
100 \& my $result = run_forked("$full_path \-q \-O \- theregister.co.uk", {\*(Aqtimeout\*(Aq => 20});
101 \& if ($result\->{\*(Aqexit_code\*(Aq} eq 0 && !$result\->{\*(Aqtimeout\*(Aq}) {
102 \& print "this is what wget returned:\en";
103 \& print $result\->{\*(Aqstdout\*(Aq};
104 \& }
105 \&
106 \& ### check for features
107 \& print "IPC::Open3 available: " . IPC::Cmd\->can_use_ipc_open3;
108 \& print "IPC::Run available: " . IPC::Cmd\->can_use_ipc_run;
109 \& print "Can capture buffer: " . IPC::Cmd\->can_capture_buffer;
110 \&
111 \& ### don\*(Aqt have IPC::Cmd be verbose, ie don\*(Aqt print to stdout or
112 \& ### stderr when running commands \-\- default is \*(Aq0\*(Aq
113 \& $IPC::Cmd::VERBOSE = 0;
114 .Ve
115 .SH DESCRIPTION
116 .IX Header "DESCRIPTION"
117 IPC::Cmd allows you to run commands platform independently,
118 interactively if desired, but have them still work.
119 .PP
120 The \f(CW\*(C`can_run\*(C'\fR function can tell you if a certain binary is installed
121 and if so where, whereas the \f(CW\*(C`run\*(C'\fR function can actually execute any
122 of the commands you give it and give you a clear return value, as well
123 as adhere to your verbosity settings.
124 .SH "CLASS METHODS"
125 .IX Header "CLASS METHODS"
126 .ie n .SS "$ipc_run_version = IPC::Cmd\->can_use_ipc_run( [VERBOSE] )"
127 .el .SS "\f(CW$ipc_run_version\fP = IPC::Cmd\->can_use_ipc_run( [VERBOSE] )"
128 .IX Subsection "$ipc_run_version = IPC::Cmd->can_use_ipc_run( [VERBOSE] )"
129 Utility function that tells you if \f(CW\*(C`IPC::Run\*(C'\fR is available.
130 If the \f(CW\*(C`verbose\*(C'\fR flag is passed, it will print diagnostic messages
131 if IPC::Run can not be found or loaded.
132 .ie n .SS "$ipc_open3_version = IPC::Cmd\->can_use_ipc_open3( [VERBOSE] )"
133 .el .SS "\f(CW$ipc_open3_version\fP = IPC::Cmd\->can_use_ipc_open3( [VERBOSE] )"
134 .IX Subsection "$ipc_open3_version = IPC::Cmd->can_use_ipc_open3( [VERBOSE] )"
135 Utility function that tells you if \f(CW\*(C`IPC::Open3\*(C'\fR is available.
136 If the verbose flag is passed, it will print diagnostic messages
137 if \f(CW\*(C`IPC::Open3\*(C'\fR can not be found or loaded.
138 .ie n .SS "$bool = IPC::Cmd\->can_capture_buffer"
139 .el .SS "\f(CW$bool\fP = IPC::Cmd\->can_capture_buffer"
140 .IX Subsection "$bool = IPC::Cmd->can_capture_buffer"
141 Utility function that tells you if \f(CW\*(C`IPC::Cmd\*(C'\fR is capable of
142 capturing buffers in it\*(Aqs current configuration.
143 .ie n .SS "$bool = IPC::Cmd\->can_use_run_forked"
144 .el .SS "\f(CW$bool\fP = IPC::Cmd\->can_use_run_forked"
145 .IX Subsection "$bool = IPC::Cmd->can_use_run_forked"
146 Utility function that tells you if \f(CW\*(C`IPC::Cmd\*(C'\fR is capable of
147 providing \f(CW\*(C`run_forked\*(C'\fR on the current platform.
148 .SH FUNCTIONS
149 .IX Header "FUNCTIONS"
150 .ie n .SS "$path = can_run( PROGRAM );"
151 .el .SS "\f(CW$path\fP = can_run( PROGRAM );"
152 .IX Subsection "$path = can_run( PROGRAM );"
153 \&\f(CW\*(C`can_run\*(C'\fR takes only one argument: the name of a binary you wish
154 to locate. \f(CW\*(C`can_run\*(C'\fR works much like the unix binary \f(CW\*(C`which\*(C'\fR or the bash
155 command \f(CW\*(C`type\*(C'\fR, which scans through your path, looking for the requested
156 binary.
157 .PP
158 Unlike \f(CW\*(C`which\*(C'\fR and \f(CW\*(C`type\*(C'\fR, this function is platform independent and
159 will also work on, for example, Win32.
160 .PP
161 If called in a scalar context it will return the full path to the binary
162 you asked for if it was found, or \f(CW\*(C`undef\*(C'\fR if it was not.
163 .PP
164 If called in a list context and the global variable \f(CW$INSTANCES\fR is a true
165 value, it will return a list of the full paths to instances
166 of the binary where found in \f(CW\*(C`PATH\*(C'\fR, or an empty list if it was not found.
167 .ie n .SS "$ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command => COMMAND, [verbose => BOOL, buffer => \e$SCALAR, timeout => DIGIT] );"
168 .el .SS "\f(CW$ok\fP | ($ok, \f(CW$err\fP, \f(CW$full_buf\fP, \f(CW$stdout_buff\fP, \f(CW$stderr_buff\fP) = run( command => COMMAND, [verbose => BOOL, buffer => \e$SCALAR, timeout => DIGIT] );"
169 .IX Subsection "$ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command => COMMAND, [verbose => BOOL, buffer => $SCALAR, timeout => DIGIT] );"
170 \&\f(CW\*(C`run\*(C'\fR takes 4 arguments:
171 .IP command 4
172 .IX Item "command"
173 This is the command to execute. It may be either a string or an array
174 reference.
175 This is a required argument.
176 .Sp
177 See "Caveats" for remarks on how commands are parsed and their
178 limitations.
179 .IP verbose 4
180 .IX Item "verbose"
181 This controls whether all output of a command should also be printed
182 to STDOUT/STDERR or should only be trapped in buffers (NOTE: buffers
183 require IPC::Run to be installed, or your system able to work with
184 IPC::Open3).
185 .Sp
186 It will default to the global setting of \f(CW$IPC::Cmd::VERBOSE\fR,
187 which by default is 0.
188 .IP buffer 4
189 .IX Item "buffer"
190 This will hold all the output of a command. It needs to be a reference
191 to a scalar.
192 Note that this will hold both the STDOUT and STDERR messages, and you
193 have no way of telling which is which.
194 If you require this distinction, run the \f(CW\*(C`run\*(C'\fR command in list context
195 and inspect the individual buffers.
196 .Sp
197 Of course, this requires that the underlying call supports buffers. See
198 the note on buffers above.
199 .IP timeout 4
200 .IX Item "timeout"
201 Sets the maximum time the command is allowed to run before aborting,
202 using the built\-in \f(CWalarm()\fR call. If the timeout is triggered, the
203 \&\f(CW\*(C`errorcode\*(C'\fR in the return value will be set to an object of the
204 \&\f(CW\*(C`IPC::Cmd::TimeOut\*(C'\fR class. See the "error message" section below for
205 details.
206 .Sp
207 Defaults to \f(CW0\fR, meaning no timeout is set.
208 .PP
209 \&\f(CW\*(C`run\*(C'\fR will return a simple \f(CW\*(C`true\*(C'\fR or \f(CW\*(C`false\*(C'\fR when called in scalar
210 context.
211 In list context, you will be returned a list of the following items:
212 .IP success 4
213 .IX Item "success"
214 A simple boolean indicating if the command executed without errors or
215 not.
216 .IP "error message" 4
217 .IX Item "error message"
218 If the first element of the return value (\f(CW\*(C`success\*(C'\fR) was 0, then some
219 error occurred. This second element is the error message the command
220 you requested exited with, if available. This is generally a pretty
221 printed value of \f(CW$?\fR or \f(CW$@\fR. See \f(CW\*(C`perldoc perlvar\*(C'\fR for details on
222 what they can contain.
223 If the error was a timeout, the \f(CW\*(C`error message\*(C'\fR will be prefixed with
224 the string \f(CW\*(C`IPC::Cmd::TimeOut\*(C'\fR, the timeout class.
225 .IP full_buffer 4
226 .IX Item "full_buffer"
227 This is an array reference containing all the output the command
228 generated.
229 Note that buffers are only available if you have IPC::Run installed,
230 or if your system is able to work with IPC::Open3 \-\- see below).
231 Otherwise, this element will be \f(CW\*(C`undef\*(C'\fR.
232 .IP out_buffer 4
233 .IX Item "out_buffer"
234 This is an array reference containing all the output sent to STDOUT the
235 command generated. The notes from "full_buffer" apply.
236 .IP error_buffer 4
237 .IX Item "error_buffer"
238 This is an arrayreference containing all the output sent to STDERR the
239 command generated. The notes from "full_buffer" apply.
240 .PP
241 See the "HOW IT WORKS" section below to see how \f(CW\*(C`IPC::Cmd\*(C'\fR decides
242 what modules or function calls to use when issuing a command.
243 .ie n .SS "$hashref = run_forked( COMMAND, { child_stdin => SCALAR, timeout => DIGIT, stdout_handler => CODEREF, stderr_handler => CODEREF} );"
244 .el .SS "\f(CW$hashref\fP = run_forked( COMMAND, { child_stdin => SCALAR, timeout => DIGIT, stdout_handler => CODEREF, stderr_handler => CODEREF} );"
245 .IX Subsection "$hashref = run_forked( COMMAND, { child_stdin => SCALAR, timeout => DIGIT, stdout_handler => CODEREF, stderr_handler => CODEREF} );"
246 \&\f(CW\*(C`run_forked\*(C'\fR is used to execute some program or a coderef,
247 optionally feed it with some input, get its return code
248 and output (both stdout and stderr into separate buffers).
249 In addition, it allows to terminate the program
250 if it takes too long to finish.
251 .PP
252 The important and distinguishing feature of run_forked
253 is execution timeout which at first seems to be
254 quite a simple task but if you think
255 that the program which you\*(Aqre spawning
256 might spawn some children itself (which
257 in their turn could do the same and so on)
258 it turns out to be not a simple issue.
259 .PP
260 \&\f(CW\*(C`run_forked\*(C'\fR is designed to survive and
261 successfully terminate almost any long running task,
262 even a fork bomb in case your system has the resources
263 to survive during given timeout.
264 .PP
265 This is achieved by creating separate watchdog process
266 which spawns the specified program in a separate
267 process session and supervises it: optionally
268 feeds it with input, stores its exit code,
269 stdout and stderr, terminates it in case
270 it runs longer than specified.
271 .PP
272 Invocation requires the command to be executed or a coderef and optionally a hashref of options:
273 .ie n .IP """timeout""" 4
274 .el .IP \f(CWtimeout\fR 4
275 .IX Item "timeout"
276 Specify in seconds how long to run the command before it is killed with SIG_KILL (9),
277 which effectively terminates it and all of its children (direct or indirect).
278 .ie n .IP """child_stdin""" 4
279 .el .IP \f(CWchild_stdin\fR 4
280 .IX Item "child_stdin"
281 Specify some text that will be passed into the \f(CW\*(C`STDIN\*(C'\fR of the executed program.
282 .ie n .IP """stdout_handler""" 4
283 .el .IP \f(CWstdout_handler\fR 4
284 .IX Item "stdout_handler"
285 Coderef of a subroutine to call when a portion of data is received on
286 STDOUT from the executing program.
287 .ie n .IP """stderr_handler""" 4
288 .el .IP \f(CWstderr_handler\fR 4
289 .IX Item "stderr_handler"
290 Coderef of a subroutine to call when a portion of data is received on
291 STDERR from the executing program.
292 .ie n .IP """wait_loop_callback""" 4
293 .el .IP \f(CWwait_loop_callback\fR 4
294 .IX Item "wait_loop_callback"
295 Coderef of a subroutine to call inside of the main waiting loop
296 (while \f(CW\*(C`run_forked\*(C'\fR waits for the external to finish or fail).
297 It is useful to stop running external process before it ends
298 by itself, e.g.
299 .Sp
300 .Vb 8
301 \& my $r = run_forked("some external command", {
302 \& \*(Aqwait_loop_callback\*(Aq => sub {
303 \& if (condition) {
304 \& kill(1, $$);
305 \& }
306 \& },
307 \& \*(Aqterminate_on_signal\*(Aq => \*(AqHUP\*(Aq,
308 \& });
309 .Ve
310 .Sp
311 Combined with \f(CW\*(C`stdout_handler\*(C'\fR and \f(CW\*(C`stderr_handler\*(C'\fR allows terminating
312 external command based on its output. Could also be used as a timer
313 without engaging with alarm (signals).
314 .Sp
315 Remember that this code could be called every millisecond (depending
316 on the output which external command generates), so try to make it
317 as lightweight as possible.
318 .ie n .IP """discard_output""" 4
319 .el .IP \f(CWdiscard_output\fR 4
320 .IX Item "discard_output"
321 Discards the buffering of the standard output and standard errors for return by \fBrun_forked()\fR.
322 With this option you have to use the std*_handlers to read what the command outputs.
323 Useful for commands that send a lot of output.
324 .ie n .IP """terminate_on_parent_sudden_death""" 4
325 .el .IP \f(CWterminate_on_parent_sudden_death\fR 4
326 .IX Item "terminate_on_parent_sudden_death"
327 Enable this option if you wish all spawned processes to be killed if the initially spawned
328 process (the parent) is killed or dies without waiting for child processes.
329 .PP
330 \&\f(CW\*(C`run_forked\*(C'\fR will return a HASHREF with the following keys:
331 .ie n .IP """exit_code""" 4
332 .el .IP \f(CWexit_code\fR 4
333 .IX Item "exit_code"
334 The exit code of the executed program.
335 .ie n .IP """timeout""" 4
336 .el .IP \f(CWtimeout\fR 4
337 .IX Item "timeout"
338 The number of seconds the program ran for before being terminated, or 0 if no timeout occurred.
339 .ie n .IP """stdout""" 4
340 .el .IP \f(CWstdout\fR 4
341 .IX Item "stdout"
342 Holds the standard output of the executed command (or empty string if
343 there was no STDOUT output or if \f(CW\*(C`discard_output\*(C'\fR was used; it\*(Aqs always defined!)
344 .ie n .IP """stderr""" 4
345 .el .IP \f(CWstderr\fR 4
346 .IX Item "stderr"
347 Holds the standard error of the executed command (or empty string if
348 there was no STDERR output or if \f(CW\*(C`discard_output\*(C'\fR was used; it\*(Aqs always defined!)
349 .ie n .IP """merged""" 4
350 .el .IP \f(CWmerged\fR 4
351 .IX Item "merged"
352 Holds the standard output and error of the executed command merged into one stream
353 (or empty string if there was no output at all or if \f(CW\*(C`discard_output\*(C'\fR was used; it\*(Aqs always defined!)
354 .ie n .IP """err_msg""" 4
355 .el .IP \f(CWerr_msg\fR 4
356 .IX Item "err_msg"
357 Holds some explanation in the case of an error.
358 .ie n .SS "$q = QUOTE"
359 .el .SS "\f(CW$q\fP = QUOTE"
360 .IX Subsection "$q = QUOTE"
361 Returns the character used for quoting strings on this platform. This is
362 usually a \f(CW\*(C`\*(Aq\*(C'\fR (single quote) on most systems, but some systems use different
363 quotes. For example, \f(CW\*(C`Win32\*(C'\fR uses \f(CW\*(C`"\*(C'\fR (double quote).
364 .PP
365 You can use it as follows:
366 .PP
367 .Vb 2
368 \& use IPC::Cmd qw[run QUOTE];
369 \& my $cmd = q[echo ] . QUOTE . q[foo bar] . QUOTE;
370 .Ve
371 .PP
372 This makes sure that \f(CW\*(C`foo bar\*(C'\fR is treated as a string, rather than two
373 separate arguments to the \f(CW\*(C`echo\*(C'\fR function.
374 .SH "HOW IT WORKS"
375 .IX Header "HOW IT WORKS"
376 \&\f(CW\*(C`run\*(C'\fR will try to execute your command using the following logic:
377 .IP \(bu 4
378 If you have \f(CW\*(C`IPC::Run\*(C'\fR installed, and the variable \f(CW$IPC::Cmd::USE_IPC_RUN\fR
379 is set to true (See the "Global Variables" section) use that to execute
380 the command. You will have the full output available in buffers, interactive commands
381 are sure to work and you are guaranteed to have your verbosity
382 settings honored cleanly.
383 .IP \(bu 4
384 Otherwise, if the variable \f(CW$IPC::Cmd::USE_IPC_OPEN3\fR is set to true
385 (See the "Global Variables" section), try to execute the command using
386 IPC::Open3. Buffers will be available on all platforms,
387 interactive commands will still execute cleanly, and also your verbosity
388 settings will be adhered to nicely;
389 .IP \(bu 4
390 Otherwise, if you have the \f(CW\*(C`verbose\*(C'\fR argument set to true, we fall back
391 to a simple \f(CWsystem()\fR call. We cannot capture any buffers, but
392 interactive commands will still work.
393 .IP \(bu 4
394 Otherwise we will try and temporarily redirect STDERR and STDOUT, do a
395 \&\f(CWsystem()\fR call with your command and then re\-open STDERR and STDOUT.
396 This is the method of last resort and will still allow you to execute
397 your commands cleanly. However, no buffers will be available.
398 .SH "Global Variables"
399 .IX Header "Global Variables"
400 The behaviour of IPC::Cmd can be altered by changing the following
401 global variables:
402 .ie n .SS $IPC::Cmd::VERBOSE
403 .el .SS \f(CW$IPC::Cmd::VERBOSE\fP
404 .IX Subsection "$IPC::Cmd::VERBOSE"
405 This controls whether IPC::Cmd will print any output from the
406 commands to the screen or not. The default is 0.
407 .ie n .SS $IPC::Cmd::USE_IPC_RUN
408 .el .SS \f(CW$IPC::Cmd::USE_IPC_RUN\fP
409 .IX Subsection "$IPC::Cmd::USE_IPC_RUN"
410 This variable controls whether IPC::Cmd will try to use IPC::Run
411 when available and suitable.
412 .ie n .SS $IPC::Cmd::USE_IPC_OPEN3
413 .el .SS \f(CW$IPC::Cmd::USE_IPC_OPEN3\fP
414 .IX Subsection "$IPC::Cmd::USE_IPC_OPEN3"
415 This variable controls whether IPC::Cmd will try to use IPC::Open3
416 when available and suitable. Defaults to true.
417 .ie n .SS $IPC::Cmd::WARN
418 .el .SS \f(CW$IPC::Cmd::WARN\fP
419 .IX Subsection "$IPC::Cmd::WARN"
420 This variable controls whether run\-time warnings should be issued, like
421 the failure to load an \f(CW\*(C`IPC::*\*(C'\fR module you explicitly requested.
422 .PP
423 Defaults to true. Turn this off at your own risk.
424 .ie n .SS $IPC::Cmd::INSTANCES
425 .el .SS \f(CW$IPC::Cmd::INSTANCES\fP
426 .IX Subsection "$IPC::Cmd::INSTANCES"
427 This variable controls whether \f(CW\*(C`can_run\*(C'\fR will return all instances of
428 the binary it finds in the \f(CW\*(C`PATH\*(C'\fR when called in a list context.
429 .PP
430 Defaults to false, set to true to enable the described behaviour.
431 .ie n .SS $IPC::Cmd::ALLOW_NULL_ARGS
432 .el .SS \f(CW$IPC::Cmd::ALLOW_NULL_ARGS\fP
433 .IX Subsection "$IPC::Cmd::ALLOW_NULL_ARGS"
434 This variable controls whether \f(CW\*(C`run\*(C'\fR will remove any empty/null arguments
435 it finds in command arguments.
436 .PP
437 Defaults to false, so it will remove null arguments. Set to true to allow
438 them.
439 .SH Caveats
440 .IX Header "Caveats"
441 .IP "Whitespace and IPC::Open3 / \fBsystem()\fR" 4
442 .IX Item "Whitespace and IPC::Open3 / system()"
443 When using \f(CW\*(C`IPC::Open3\*(C'\fR or \f(CW\*(C`system\*(C'\fR, if you provide a string as the
444 \&\f(CW\*(C`command\*(C'\fR argument, it is assumed to be appropriately escaped. You can
445 use the \f(CW\*(C`QUOTE\*(C'\fR constant to use as a portable quote character (see above).
446 However, if you provide an array reference, special rules apply:
447 .Sp
448 If your command contains \fBspecial characters\fR (< > | &), it will
449 be internally stringified before executing the command, to avoid that these
450 special characters are escaped and passed as arguments instead of retaining
451 their special meaning.
452 .Sp
453 However, if the command contained arguments that contained whitespace,
454 stringifying the command would lose the significance of the whitespace.
455 Therefore, \f(CW\*(C`IPC::Cmd\*(C'\fR will quote any arguments containing whitespace in your
456 command if the command is passed as an arrayref and contains special characters.
457 .IP "Whitespace and IPC::Run" 4
458 .IX Item "Whitespace and IPC::Run"
459 When using \f(CW\*(C`IPC::Run\*(C'\fR, if you provide a string as the \f(CW\*(C`command\*(C'\fR argument,
460 the string will be split on whitespace to determine the individual elements
461 of your command. Although this will usually just Do What You Mean, it may
462 break if you have files or commands with whitespace in them.
463 .Sp
464 If you do not wish this to happen, you should provide an array
465 reference, where all parts of your command are already separated out.
466 Note however, if there are extra or spurious whitespaces in these parts,
467 the parser or underlying code may not interpret it correctly, and
468 cause an error.
469 .Sp
470 Example:
471 The following code
472 .Sp
473 .Vb 1
474 \& gzip \-cdf foo.tar.gz | tar \-xf \-
475 .Ve
476 .Sp
477 should either be passed as
478 .Sp
479 .Vb 1
480 \& "gzip \-cdf foo.tar.gz | tar \-xf \-"
481 .Ve
482 .Sp
483 or as
484 .Sp
485 .Vb 1
486 \& [\*(Aqgzip\*(Aq, \*(Aq\-cdf\*(Aq, \*(Aqfoo.tar.gz\*(Aq, \*(Aq|\*(Aq, \*(Aqtar\*(Aq, \*(Aq\-xf\*(Aq, \*(Aq\-\*(Aq]
487 .Ve
488 .Sp
489 But take care not to pass it as, for example
490 .Sp
491 .Vb 1
492 \& [\*(Aqgzip \-cdf foo.tar.gz\*(Aq, \*(Aq|\*(Aq, \*(Aqtar \-xf \-\*(Aq]
493 .Ve
494 .Sp
495 Since this will lead to issues as described above.
496 .IP "IO Redirect" 4
497 .IX Item "IO Redirect"
498 Currently it is too complicated to parse your command for IO
499 redirections. For capturing STDOUT or STDERR there is a work around
500 however, since you can just inspect your buffers for the contents.
501 .IP "Interleaving STDOUT/STDERR" 4
502 .IX Item "Interleaving STDOUT/STDERR"
503 Neither IPC::Run nor IPC::Open3 can interleave STDOUT and STDERR. For short
504 bursts of output from a program, e.g. this sample,
505 .Sp
506 .Vb 3
507 \& for ( 1..4 ) {
508 \& $_ % 2 ? print STDOUT $_ : print STDERR $_;
509 \& }
510 .Ve
511 .Sp
512 IPC::[Run|Open3] will first read all of STDOUT, then all of STDERR, meaning
513 the output looks like \*(Aq13\*(Aq on STDOUT and \*(Aq24\*(Aq on STDERR, instead of
514 .Sp
515 .Vb 4
516 \& 1
517 \& 2
518 \& 3
519 \& 4
520 .Ve
521 .Sp
522 This has been recorded in rt.cpan.org as bug #37532: Unable to interleave
523 STDOUT and STDERR.
524 .SH "See Also"
525 .IX Header "See Also"
526 IPC::Run, IPC::Open3
527 .SH ACKNOWLEDGEMENTS
528 .IX Header "ACKNOWLEDGEMENTS"
529 Thanks to James Mastros and Martijn van der Streek for their
530 help in getting IPC::Open3 to behave nicely.
531 .PP
532 Thanks to Petya Kohts for the \f(CW\*(C`run_forked\*(C'\fR code.
533 .SH "BUG REPORTS"
534 .IX Header "BUG REPORTS"
535 Please report bugs or other issues to <bug\-ipc\[email protected]>.
536 .SH AUTHOR
537 .IX Header "AUTHOR"
538 Original author: Jos Boumans <[email protected]>.
539 Current maintainer: Chris Williams <[email protected]>.
540 .SH COPYRIGHT
541 .IX Header "COPYRIGHT"
542 This library is free software; you may redistribute and/or modify it
543 under the same terms as Perl itself.