File: Win32Process.pm

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (86 lines) | stat: -rw-r--r-- 2,057 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package IPC::Run::Win32Process;

=pod

=head1 NAME

IPC::Run::Win32Process -- deliver nonstandard command lines via IPC::Run.

=head1 SYNOPSIS

   use File::Spec ();
   use IPC::Run qw(run);
   use IPC::Run::Win32Process ();
   use Win32 ();

   $find_exe = File::Spec->catfile(Win32::GetFolderPath(Win32::CSIDL_SYSTEM),
                                   'find.exe');
   run(IPC::Run::Win32Process->new($ENV{COMSPEC}, q{cmd.exe /c echo ""}),
       '|', IPC::Run::Win32Process->new($find_exe, q{find_exe """"""}),
       '>', \$out);

=head1 DESCRIPTION

This class facilitates executing Windows programs that don't use L<standard
command line parsing
rules|https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args#parsing-c-command-line-arguments>.
Notable programs having nonstandard rules include F<cmd.exe>, F<cscript.exe>,
and Cygwin programs called from non-Cygwin programs.  IPC::Run will use the two
strings, verbatim, as the lpApplicationName and lpCommandLine arguments of
CreateProcessA().  This furnishes unfiltered control over the child process
command line.

=head1 FUNCTIONS & METHODS

=over

=cut

use strict;
use warnings;
use Carp;

use overload '""' => sub {
    my ($self) = @_;
    return join(
        '',
        'IPC::Run::Win32Process(',
        $self->{lpApplicationName},
        ', ',
        $self->{lpCommandLine},
        ')'
    );
};

use vars qw{$VERSION};

BEGIN {
    $VERSION = '20231003.0';
}

=item new

   IPC::Run::Win32Process->new( $lpApplicationName, $lpCommandLine );
   IPC::Run::Win32Process->new( $ENV{COMSPEC}, q{cmd.exe /c echo ""} );

Constructor.

=back

=cut

sub new {
    my ( $class, $lpApplicationName, $lpCommandLine ) = @_;
    $class = ref $class || $class;

    croak "missing lpApplicationName" if !defined $lpApplicationName;
    croak "missing lpCommandLine"     if !defined $lpCommandLine;

    my IPC::Run::Win32Process $self = bless {}, $class;
    $self->{lpApplicationName} = $lpApplicationName;
    $self->{lpCommandLine}     = $lpCommandLine;

    return $self;
}

1;