Skip to main content.
home | support | download

Back to List Archive

Running programs on Windows

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Mon Sep 27 2004 - 19:37:15 GMT
Following our discussions last week... can I get a few Windows users
to help test something?

I use the Perl module IPC::Open2 to run an external program on
Windows:

    require IPC::Open2;
    my ( $rdrfh, $wtrfh );

    my @command = map { s/"/\\"/g; qq["$_"] }  @args;

    my $pid = IPC::Open2::open2($rdrfh, $wtrfh, @command );

I have a few questions about this.

First, that "map" takes all the arguments (parameters) and places them
in double quotes.  That was to make sure that any one argument that
contains a space character is still treated as a single argument.

I just fired up my door stop running Windows 98 and it seems like
those quotes are not needed (although they are stripped by Windows).
I assume that "map" was added for some reason -- so maybe some other
version of Windows requires those quotes.

So, I have pair of two short programs that I'd like tested on other
versions of Windows.  The first program calls the second program, and
the second program prints out the arguments it receives:

moseley@bumby:~$ cat test.pl
#!/usr/bin/perl -w
use strict;

use IPC::Open2;

my @command = ( 'perl', 'my test.pl', 'first arg1', '"second arg2"' );

my $pid = IPC::Open2::open2( \*r, \*w, @command );

print "Pid = $pid\n";
print "output:\n";
print while $_ = <r>;
print "done\n";
waitpid $pid,0 || warn $!;



moseley@bumby:~$ cat 'my test.pl'
#!/usr/bin/perl -w
use strict;

print "$$ [$_]\n" for @ARGV;
print "$$ done\n";

The, here's the output I'm seeing.  Notice that the arguments are
passed as expected (although Windows is stripping the quotes from the
second set.

moseley@bumby:~$ cat output
Pid = 278565
output:
278565 [first arg1]
278565 [second arg2]
278565 done
done


The other question is about the $pid returned from the open2() call.
On Windows98 it's the same PID each time I run the program.  On other
Windows versions is the PID different?  That is, if open2() is called
more than once will it return different PIDs each time?

Thanks,





-- 
Bill Moseley
moseley@hank.org

Unsubscribe from or help with the swish-e list: 
   http://swish-e.org/Discussion/

Help with Swish-e:
   http://swish-e.org/current/docs
   swish-e@sunsite.berkeley.edu
Received on Mon Sep 27 12:37:30 2004