@@ -413,8 +413,8 @@ to the systems' shell:
413413
414414or a list of commands, io operations, and/or timers/timeouts to execute.
415415Consecutive commands must be separated by a pipe operator '|' or an '&'.
416- External commands are passed in as array references, and, on systems
417- supporting fork(), Perl code may be passed in as subs:
416+ External commands are passed in as array references or L<IPC::Run::Win32Process>
417+ objects. On systems supporting fork(), Perl code may be passed in as subs:
418418
419419 run \@cmd;
420420 run \@cmd1, '|', \@cmd2;
@@ -1240,6 +1240,33 @@ sub _search_path {
12401240 croak " Command '$cmd_name ' not found in " . join ( " , " , @searched_in );
12411241}
12421242
1243+ # Translate a command or CODE reference (a $kid->{VAL}) to a list of strings
1244+ # suitable for passing to _debug().
1245+ sub _debugstrings {
1246+ my $operand = shift ;
1247+ if ( !defined $operand ) {
1248+ return ' <undef>' ;
1249+ }
1250+
1251+ my $ref = ref $operand ;
1252+ if ( !$ref ) {
1253+ return length $operand < 50
1254+ ? " '$operand '"
1255+ : join ( ' ' , " '" , substr ( $operand , 0, 10 ), " ...'" );
1256+ }
1257+ elsif ( $ref eq ' ARRAY' ) {
1258+ return (
1259+ ' [ ' ,
1260+ join ( " " , map /[^\w.-]/ ? " '$_ '" : $_ , @$operand ),
1261+ ' ]'
1262+ );
1263+ }
1264+ elsif ( UNIVERSAL::isa( $operand , ' IPC::Run::Win32Process' ) ) {
1265+ return " $operand " ;
1266+ }
1267+ return $ref ;
1268+ }
1269+
12431270sub _empty ($) { !( defined $_ [0] && length $_ [0] ) }
12441271
12451272# # 'safe' versions of otherwise fun things to do. See also IPC::Run::Win32Helper.
@@ -1375,6 +1402,9 @@ sub _spawn {
13751402 my IPC::Run $self = shift ;
13761403 my ($kid ) = @_ ;
13771404
1405+ croak " Can't spawn IPC::Run::Win32Process except on Win32"
1406+ if UNIVERSAL::isa( $kid -> {VAL }, ' IPC::Run::Win32Process' );
1407+
13781408 _debug " opening sync pipe " , $kid -> {PID } if _debugging_details;
13791409 my $sync_reader_fd ;
13801410 ( $sync_reader_fd , $self -> {SYNC_WRITER_FD } ) = _pipe;
@@ -1730,24 +1760,12 @@ sub harness {
17301760 for ( shift @args ) {
17311761 eval {
17321762 $first_parse = 1;
1733- _debug(
1734- " parsing " ,
1735- defined $_
1736- ? ref $_ eq ' ARRAY'
1737- ? ( ' [ ' , join ( ' , ' , map " '$_ '" , @$_ ), ' ]' )
1738- : (
1739- ref $_
1740- || (
1741- length $_ < 50
1742- ? " '$_ '"
1743- : join ( ' ' , " '" , substr ( $_ , 0, 10 ), " ...'" )
1744- )
1745- )
1746- : ' <undef>'
1747- ) if _debugging;
1763+ _debug( " parsing " , _debugstrings($_ ) ) if _debugging;
17481764
17491765 REPARSE:
1750- if ( ref eq ' ARRAY' || ( !$cur_kid && ref eq ' CODE' ) ) {
1766+ if ( ref eq ' ARRAY'
1767+ || UNIVERSAL::isa( $_ , ' IPC::Run::Win32Process' )
1768+ || ( !$cur_kid && ref eq ' CODE' ) ) {
17511769 croak " Process control symbol ('|', '&') missing" if $cur_kid ;
17521770 croak " Can't spawn a subroutine on Win32"
17531771 if Win32_MODE && ref eq " CODE" ;
@@ -2077,7 +2095,7 @@ sub _open_pipes {
20772095 # # Loop through the kids and their OPS, interpreting any that require
20782096 # # parent-side actions.
20792097 for my $kid ( @{ $self -> {KIDS } } ) {
2080- unless ( ref $kid -> {VAL } eq ' CODE ' ) {
2098+ if ( ref $kid -> {VAL } eq ' ARRAY ' ) {
20812099 $kid -> {PATH } = _search_path $kid -> {VAL }-> [0];
20822100 }
20832101 if ( defined $pipe_read_fd ) {
@@ -2789,14 +2807,8 @@ sub start {
27892807 { my $ofh = select STDERR ; my $of = $| ; $| = 1; $| = $of ; select $ofh ; }
27902808 for my $kid ( @{ $self -> {KIDS } } ) {
27912809 $kid -> {RESULT } = undef ;
2792- _debug " child: " ,
2793- ref ( $kid -> {VAL } ) eq " CODE"
2794- ? " CODE ref"
2795- : (
2796- " `" ,
2797- join ( " " , map /[^\w.-]/ ? " '$_ '" : $_ , @{ $kid -> {VAL } } ),
2798- " `"
2799- ) if _debugging_details;
2810+ _debug " child: " , _debugstrings( $kid -> {VAL } )
2811+ if _debugging_details;
28002812 eval {
28012813 croak " simulated failure of fork"
28022814 if $self -> {_simulate_fork_failure };
@@ -2807,17 +2819,20 @@ sub start {
28072819# # TODO: Test and debug spawning code. Someday.
28082820 _debug(
28092821 ' spawning ' ,
2810- join (
2811- ' ' ,
2812- map ( " '$_ '" ,
2813- ( $kid -> {PATH }, @{ $kid -> {VAL } }[ 1 .. $# { $kid -> {VAL } } ] ) )
2822+ _debugstrings(
2823+ [
2824+ $kid -> {PATH },
2825+ @{ $kid -> {VAL } }[ 1 .. $# { $kid -> {VAL } } ]
2826+ ]
28142827 )
2815- ) if _debugging;
2828+ ) if $kid -> { PATH } && _debugging;
28162829 # # The external kid wouldn't know what to do with it anyway.
28172830 # # This is only used by the "helper" pump processes on Win32.
28182831 _dont_inherit( $self -> {DEBUG_FD } );
28192832 ( $kid -> {PID }, $kid -> {PROCESS } ) = IPC::Run::Win32Helper::win32_spawn(
2820- [ $kid -> {PATH }, @{ $kid -> {VAL } }[ 1 .. $# { $kid -> {VAL } } ] ],
2833+ ref ( $kid -> {VAL } ) eq " ARRAY"
2834+ ? [ $kid -> {PATH }, @{ $kid -> {VAL } }[ 1 .. $# { $kid -> {VAL } } ] ]
2835+ : $kid -> {VAL },
28212836 $kid -> {OPS },
28222837 );
28232838 _debug " spawn() = " , $kid -> {PID } if _debugging;
@@ -4170,8 +4185,8 @@ rules|https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args#p
41704185will see an C<argv > that matches the array reference specifying the command.
41714186Some programs use different rules to parse their command line. Notable examples
41724187include F<cmd.exe> , F<cscript.exe> , and Cygwin programs called from non-Cygwin
4173- programs. Use L<Win32::Process> , not IPC::Run, to call these and other
4174- nonstandard programs.
4188+ programs. Use L<IPC::Run::Win32Process> to call these and other nonstandard
4189+ programs.
41754190
41764191=item batch files
41774192
0 commit comments