| 1 | package IPC::Run::Win32Process; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | IPC::Run::Win32Process -- deliver nonstandard command lines via IPC::Run. | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use File::Spec (); | ||
| 12 | use IPC::Run qw(run); | ||
| 13 | use IPC::Run::Win32Process (); | ||
| 14 | use Win32 (); | ||
| 15 | |||
| 16 | $find_exe = File::Spec->catfile(Win32::GetFolderPath(Win32::CSIDL_SYSTEM), | ||
| 17 | 'find.exe'); | ||
| 18 | run(IPC::Run::Win32Process->new($ENV{COMSPEC}, q{cmd.exe /c echo ""}), | ||
| 19 | '|', IPC::Run::Win32Process->new($find_exe, q{find_exe """"""}), | ||
| 20 | '>', \$out); | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | This class facilitates executing Windows programs that don't use L<standard | ||
| 25 | command line parsing | ||
| 26 | rules|https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args#parsing-c-command-line-arguments>. | ||
| 27 | Notable programs having nonstandard rules include F<cmd.exe>, F<cscript.exe>, | ||
| 28 | and Cygwin programs called from non-Cygwin programs. IPC::Run will use the two | ||
| 29 | strings, verbatim, as the lpApplicationName and lpCommandLine arguments of | ||
| 30 | CreateProcessA(). This furnishes unfiltered control over the child process | ||
| 31 | command line. | ||
| 32 | |||
| 33 | =head1 FUNCTIONS & METHODS | ||
| 34 | |||
| 35 | =over | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | use strict; | ||
| 40 | use warnings; | ||
| 41 | use Carp; | ||
| 42 | |||
| 43 | use overload '""' => sub { | ||
| 44 | my ($self) = @_; | ||
| 45 | return join( | ||
| 46 | '', | ||
| 47 | 'IPC::Run::Win32Process(', | ||
| 48 | $self->{lpApplicationName}, | ||
| 49 | ', ', | ||
| 50 | $self->{lpCommandLine}, | ||
| 51 | ')' | ||
| 52 | ); | ||
| 53 | }; | ||
| 54 | |||
| 55 | use vars qw{$VERSION}; | ||
| 56 | |||
| 57 | BEGIN { | ||
| 58 | $VERSION = '20250715.0_01'; | ||
| 59 | } | ||
| 60 | |||
| 61 | =item new | ||
| 62 | |||
| 63 | IPC::Run::Win32Process->new( $lpApplicationName, $lpCommandLine ); | ||
| 64 | IPC::Run::Win32Process->new( $ENV{COMSPEC}, q{cmd.exe /c echo ""} ); | ||
| 65 | |||
| 66 | Constructor. | ||
| 67 | |||
| 68 | =back | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | sub new { | ||
| 73 | my ( $class, $lpApplicationName, $lpCommandLine ) = @_; | ||
| 74 | $class = ref $class || $class; | ||
| 75 | |||
| 76 | croak "missing lpApplicationName" if !defined $lpApplicationName; | ||
| 77 | croak "missing lpCommandLine" if !defined $lpCommandLine; | ||
| 78 | |||
| 79 | my IPC::Run::Win32Process $self = bless {}, $class; | ||
| 80 | $self->{lpApplicationName} = $lpApplicationName; | ||
| 81 | $self->{lpCommandLine} = $lpCommandLine; | ||
| 82 | |||
| 83 | return $self; | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; |