You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2003/06/04 08:48:49 UTC

[mp2] apache/subprocess on Win32

Hi,
   On Win32, the apache/subprocess tests fail on Win32.
This is due to the following: currently, the tests do
something like

   @argv = qw(potentially something);
   $command = catfile $target_dir, "some_script.pl";
   Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);

The problem on Win32 is that $command isn't associated with Perl.
To fix this, one could do one of two things.

- create a "some_script.bat" with pl2bat, use
   $command = catfile $target_dir, "some_script.bat";
and insert a
   $r->subprocess_env->set(PATH => $Config{bin});
before invoking the script.

- use
    $command = $Config{perlpath}; # or perhaps better $^X
    @list = ("some_script.pl", @argv);
    Apache::SubProcess::spawn_proc_prog($r, $command, \@list);
(the potentially nicer looking
    $command = "$Config{perlpath} some_script.pl";
    Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
doesn't work - I think it interprets $command as one single
command - Win32 is famous for problems with quoting command-line
things).

Either of the above works - does anyone have a strong
preference one way or another?

Incidentally, for both, subtests 3 and 4 need
some massaging for line endings - either have
   my $value = "some text\r\n";
or use
   $output =~ s!\r!!;
Although, with perlio the :crlf filter would be
available, which would be neater ...

best regards,
randy kobes

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] apache/subprocess on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:

>>>     my $target_dir = catfile $vars->{documentroot}, "util";
>>>
>>>+    my $perl = catfile $Config{bin},
>>>+        (Apache::TestConfig::WIN32 ? 'perl.exe' : 'perl');
>>>+
>>
>>In that case, we do know the path to perl, it's stored in Apache::Build:
>>
>>     require Apache::Build;
>>     my $build = Apache::Build->build_config;
>>     my $perl_path = $build->perl_config('perlpath');
>>
>>$Config{bin}/perl is definitely wrong, as it can be $Config{bin}/perl5.9.0 for
>>example. Or anything else for that purpose. e.g.  $Config{bin}/python to
>>confuse the management ;)
> 
> 
> Good point :) -  a revised diff appears below using Apache::Build.

The patch didn't apply for me, but I've wrestled it in manually. Works fine 
for me!

I've done a few tiny tweaks and attached a version that applies cleanly (e.g. 
$perlpath can be retrieved at compile time).

+1 to commit. Great work, Randy!

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [mp2] apache/subprocess on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 5 Jun 2003, Stas Bekman wrote:

> Randy Kobes wrote:
[ .. ]
> > Yes, it does - thanks. Here's a diff that enables all the
> > apache/subprocess tests to pass on Win32 (I haven't tested
> > it on Unix):
> >
> > ==========================================================
> > Index: subprocess.pm
> > ===================================================================
> > RCS file: /home/cvs/modperl-2.0/t/response/TestApache/subprocess.pm,v
> > retrieving revision 1.13
> > diff -u -r1.13 subprocess.pm
> > --- subprocess.pm	8 Apr 2003 02:05:34 -0000	1.13
> > +++ subprocess.pm	5 Jun 2003 06:51:32 -0000
> > @@ -5,6 +5,7 @@
> >
> >  use Apache::Test;
> >  use Apache::TestUtil;
> > +require Apache::TestConfig;
> >
> >  use File::Spec::Functions qw(catfile catdir);
> >  use IO::Select ();
> > @@ -44,11 +45,16 @@
> >
> >      my $target_dir = catfile $vars->{documentroot}, "util";
> >
> > +    my $perl = catfile $Config{bin},
> > +        (Apache::TestConfig::WIN32 ? 'perl.exe' : 'perl');
> > +
>
> In that case, we do know the path to perl, it's stored in Apache::Build:
>
>      require Apache::Build;
>      my $build = Apache::Build->build_config;
>      my $perl_path = $build->perl_config('perlpath');
>
> $Config{bin}/perl is definitely wrong, as it can be $Config{bin}/perl5.9.0 for
> example. Or anything else for that purpose. e.g.  $Config{bin}/python to
> confuse the management ;)

Good point :) -  a revised diff appears below using Apache::Build.

>
> >      {
> >          # test: passing argv + scalar context
> >          my $command = catfile $target_dir, "argv.pl";
> >          my @argv = qw(foo bar);
> > -        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> > +        my $out_fh = Apache::TestConfig::WIN32 ?
> > +            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command, @argv]) :
> > +                  Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
>
> Also any reason for not doing the same for all? the WIN32 case should work
> just fine for others, no?
> [...]
> > -        my $output = read_data($out_fh);
> > +        (my $output = read_data($out_fh)) =~ s/[\r\n]{1,2}/\r\n/;
>
> I guess we leave it for now, but later will probably abstract it into a
> function, once we need it in other tests, probably put XXX so we will remember.
>
> please test with using Apache::Build to get the perl path and if it works,
> I'll test on UNIX.

Here's a revised diff, using the same syntax for all. This
works on Win32, but again, I haven't tested it on Unix.

======================================================================
Index: subprocess.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestApache/subprocess.pm,v
retrieving revision 1.13
diff -u -r1.13 subprocess.pm
--- subprocess.pm	8 Apr 2003 02:05:34 -0000	1.13
+++ subprocess.pm	5 Jun 2003 07:59:54 -0000
@@ -5,6 +5,7 @@

 use Apache::Test;
 use Apache::TestUtil;
+require Apache::Build;

 use File::Spec::Functions qw(catfile catdir);
 use IO::Select ();
@@ -44,11 +45,14 @@

     my $target_dir = catfile $vars->{documentroot}, "util";

+    my $perl = Apache::Build->build_config()->perl_config('perlpath');
+
     {
         # test: passing argv + scalar context
-        my $command = catfile $target_dir, "argv.pl";
+        my $script = catfile $target_dir, "argv.pl";
         my @argv = qw(foo bar);
-        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
+        my $out_fh =
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$script, @argv]);
         my $output = read_data($out_fh);
         ok t_cmp(\@argv,
                  [split / /, $output],
@@ -58,10 +62,11 @@

     {
         # test: passing env to subprocess through subprocess_env
-        my $command = catfile $target_dir, "env.pl";
+        my $script = catfile $target_dir, "env.pl";
         my $value = "my cool proc";
         $r->subprocess_env->set(SubProcess => $value);
-        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $out_fh =
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$script]);
         my $output = read_data($out_fh);
         ok t_cmp($value,
                  $output,
@@ -71,12 +76,12 @@

     {
         # test: subproc's stdin -> stdout + list context
-        my $command = catfile $target_dir, "in_out.pl";
-        my $value = "my cool proc\n"; # must have \n for <IN>
-        my ($in_fh, $out_fh, $err_fh) =
-            Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $script = catfile $target_dir, "in_out.pl";
+        my $value = "my cool proc\r\n"; # must have \n for <IN>
+        my ($in_fh, $out_fh, $err_fh) =
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$script]);
         print $in_fh $value;
-        my $output = read_data($out_fh);
+        (my $output = read_data($out_fh)) =~ s/[\r\n]{1,2}/\r\n/;
         ok t_cmp($value,
                  $output,
                  "testing subproc's stdin -> stdout + list context"
@@ -85,12 +90,12 @@

     {
         # test: subproc's stdin -> stderr + list context
-        my $command = catfile $target_dir, "in_err.pl";
-        my $value = "my stderr\n"; # must have \n for <IN>
-        my ($in_fh, $out_fh, $err_fh) =
-            Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $script = catfile $target_dir, "in_err.pl";
+        my $value = "my stderr\r\n"; # must have \n for <IN>
+        my ($in_fh, $out_fh, $err_fh) =
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$script]);
         print $in_fh $value;
-        my $output = read_data($err_fh);
+        (my $output = read_data($err_fh)) =~ s/[\r\n]{1,2}/\r\n/;
         ok t_cmp($value,
                  $output,
                  "testing subproc's stdin -> stderr + list context"
=======================================================================
Thanks.
-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] apache/subprocess on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 4 Jun 2003, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>>Hi,
>>>   On Win32, the apache/subprocess tests fail on Win32.
>>>This is due to the following: currently, the tests do
>>>something like
>>>   @argv = qw(potentially something);
>>>   $command = catfile $target_dir, "some_script.pl";
>>>   Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
>>>The problem on Win32 is that $command isn't associated with Perl.
>>>To fix this, one could do one of two things.
>>>
>>>- create a "some_script.bat" with pl2bat, use
>>>   $command = catfile $target_dir, "some_script.bat";
>>>and insert a
>>>   $r->subprocess_env->set(PATH => $Config{bin});
>>>before invoking the script.
>>>
>>>- use
>>>    $command = $Config{perlpath}; # or perhaps better $^X
>>>    @list = ("some_script.pl", @argv);
>>>    Apache::SubProcess::spawn_proc_prog($r, $command, \@list);
>>>(the potentially nicer looking
>>>    $command = "$Config{perlpath} some_script.pl";
>>>    Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
>>>doesn't work - I think it interprets $command as one single
>>>command - Win32 is famous for problems with quoting command-line
>>>things).
>>>
>>>Either of the above works - does anyone have a strong
>>>preference one way or another?
>>
>>I prefer 2nd, since it doesn't force us to modify the filename.
>>However I'd check whether $Config{perlpath} works everywhere.
>>Perhaps check perl test suite to see what it uses? I remember
>>there was a discussion of may be using $^X. or both.
> 
> 
> Would you believe that $^X is reported as Apache.exe?

oops

>>otherwise +1
>>
>>
>>>Incidentally, for both, subtests 3 and 4 need
>>>some massaging for line endings - either have
>>>   my $value = "some text\r\n";
>>>or use
>>>   $output =~ s!\r!!;
>>>Although, with perlio the :crlf filter would be
>>>available, which would be neater ...
>>
>>what about mac? there is no \r there. I guess we need to do what CGI.pm does
>>or is there a standard module that defines $CRLF?
>>
>>In any case we could probably always write "\r\n" (e.g. "some text\r\n") and
>>then after reading the output do:
>>
>>s/[\r\n]{1,2}/\r\n/;
>>
>>and only then compare. Will that work?
> 
> 
> Yes, it does - thanks. Here's a diff that enables all the
> apache/subprocess tests to pass on Win32 (I haven't tested
> it on Unix):
> 
> ==========================================================
> Index: subprocess.pm
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/response/TestApache/subprocess.pm,v
> retrieving revision 1.13
> diff -u -r1.13 subprocess.pm
> --- subprocess.pm	8 Apr 2003 02:05:34 -0000	1.13
> +++ subprocess.pm	5 Jun 2003 06:51:32 -0000
> @@ -5,6 +5,7 @@
> 
>  use Apache::Test;
>  use Apache::TestUtil;
> +require Apache::TestConfig;
> 
>  use File::Spec::Functions qw(catfile catdir);
>  use IO::Select ();
> @@ -44,11 +45,16 @@
> 
>      my $target_dir = catfile $vars->{documentroot}, "util";
> 
> +    my $perl = catfile $Config{bin},
> +        (Apache::TestConfig::WIN32 ? 'perl.exe' : 'perl');
> +

In that case, we do know the path to perl, it's stored in Apache::Build:

     require Apache::Build;
     my $build = Apache::Build->build_config;
     my $perl_path = $build->perl_config('perlpath');

$Config{bin}/perl is definitely wrong, as it can be $Config{bin}/perl5.9.0 for 
example. Or anything else for that purpose. e.g.  $Config{bin}/python to 
confuse the management ;)

>      {
>          # test: passing argv + scalar context
>          my $command = catfile $target_dir, "argv.pl";
>          my @argv = qw(foo bar);
> -        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> +        my $out_fh = Apache::TestConfig::WIN32 ?
> +            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command, @argv]) :
> +                  Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);

Also any reason for not doing the same for all? the WIN32 case should work 
just fine for others, no?
[...]
> -        my $output = read_data($out_fh);
> +        (my $output = read_data($out_fh)) =~ s/[\r\n]{1,2}/\r\n/;

I guess we leave it for now, but later will probably abstract it into a 
function, once we need it in other tests, probably put XXX so we will remember.

please test with using Apache::Build to get the perl path and if it works, 
I'll test on UNIX.

Thanks Randy.

FWIW, perl uses:

     my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;

but as you said, Apache.exe is not what we want ;)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] apache/subprocess on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 4 Jun 2003, Stas Bekman wrote:

> Randy Kobes wrote:
> > Hi,
> >    On Win32, the apache/subprocess tests fail on Win32.
> > This is due to the following: currently, the tests do
> > something like
> >    @argv = qw(potentially something);
> >    $command = catfile $target_dir, "some_script.pl";
> >    Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> > The problem on Win32 is that $command isn't associated with Perl.
> > To fix this, one could do one of two things.
> >
> > - create a "some_script.bat" with pl2bat, use
> >    $command = catfile $target_dir, "some_script.bat";
> > and insert a
> >    $r->subprocess_env->set(PATH => $Config{bin});
> > before invoking the script.
> >
> > - use
> >     $command = $Config{perlpath}; # or perhaps better $^X
> >     @list = ("some_script.pl", @argv);
> >     Apache::SubProcess::spawn_proc_prog($r, $command, \@list);
> > (the potentially nicer looking
> >     $command = "$Config{perlpath} some_script.pl";
> >     Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> > doesn't work - I think it interprets $command as one single
> > command - Win32 is famous for problems with quoting command-line
> > things).
> >
> > Either of the above works - does anyone have a strong
> > preference one way or another?
>
> I prefer 2nd, since it doesn't force us to modify the filename.
> However I'd check whether $Config{perlpath} works everywhere.
> Perhaps check perl test suite to see what it uses? I remember
> there was a discussion of may be using $^X. or both.

Would you believe that $^X is reported as Apache.exe?

>
> otherwise +1
>
> > Incidentally, for both, subtests 3 and 4 need
> > some massaging for line endings - either have
> >    my $value = "some text\r\n";
> > or use
> >    $output =~ s!\r!!;
> > Although, with perlio the :crlf filter would be
> > available, which would be neater ...
>
> what about mac? there is no \r there. I guess we need to do what CGI.pm does
> or is there a standard module that defines $CRLF?
>
> In any case we could probably always write "\r\n" (e.g. "some text\r\n") and
> then after reading the output do:
>
> s/[\r\n]{1,2}/\r\n/;
>
> and only then compare. Will that work?

Yes, it does - thanks. Here's a diff that enables all the
apache/subprocess tests to pass on Win32 (I haven't tested
it on Unix):

==========================================================
Index: subprocess.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestApache/subprocess.pm,v
retrieving revision 1.13
diff -u -r1.13 subprocess.pm
--- subprocess.pm	8 Apr 2003 02:05:34 -0000	1.13
+++ subprocess.pm	5 Jun 2003 06:51:32 -0000
@@ -5,6 +5,7 @@

 use Apache::Test;
 use Apache::TestUtil;
+require Apache::TestConfig;

 use File::Spec::Functions qw(catfile catdir);
 use IO::Select ();
@@ -44,11 +45,16 @@

     my $target_dir = catfile $vars->{documentroot}, "util";

+    my $perl = catfile $Config{bin},
+        (Apache::TestConfig::WIN32 ? 'perl.exe' : 'perl');
+
     {
         # test: passing argv + scalar context
         my $command = catfile $target_dir, "argv.pl";
         my @argv = qw(foo bar);
-        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
+        my $out_fh = Apache::TestConfig::WIN32 ?
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command, @argv]) :
+                  Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
         my $output = read_data($out_fh);
         ok t_cmp(\@argv,
                  [split / /, $output],
@@ -61,7 +67,9 @@
         my $command = catfile $target_dir, "env.pl";
         my $value = "my cool proc";
         $r->subprocess_env->set(SubProcess => $value);
-        my $out_fh = Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $out_fh = Apache::TestConfig::WIN32 ?
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command]) :
+                  Apache::SubProcess::spawn_proc_prog($r, $command);
         my $output = read_data($out_fh);
         ok t_cmp($value,
                  $output,
@@ -72,11 +80,12 @@
     {
         # test: subproc's stdin -> stdout + list context
         my $command = catfile $target_dir, "in_out.pl";
-        my $value = "my cool proc\n"; # must have \n for <IN>
-        my ($in_fh, $out_fh, $err_fh) =
-            Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $value = "my cool proc\r\n"; # must have \n for <IN>
+        my ($in_fh, $out_fh, $err_fh) = Apache::TestConfig::WIN32 ?
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command]) :
+                  Apache::SubProcess::spawn_proc_prog($r, $command);
         print $in_fh $value;
-        my $output = read_data($out_fh);
+        (my $output = read_data($out_fh)) =~ s/[\r\n]{1,2}/\r\n/;
         ok t_cmp($value,
                  $output,
                  "testing subproc's stdin -> stdout + list context"
@@ -86,11 +95,12 @@
     {
         # test: subproc's stdin -> stderr + list context
         my $command = catfile $target_dir, "in_err.pl";
-        my $value = "my stderr\n"; # must have \n for <IN>
-        my ($in_fh, $out_fh, $err_fh) =
-            Apache::SubProcess::spawn_proc_prog($r, $command);
+        my $value = "my stderr\r\n"; # must have \n for <IN>
+        my ($in_fh, $out_fh, $err_fh) = Apache::TestConfig::WIN32 ?
+            Apache::SubProcess::spawn_proc_prog($r, $perl, [$command]) :
+                  Apache::SubProcess::spawn_proc_prog($r, $command);
         print $in_fh $value;
-        my $output = read_data($err_fh);
+        (my $output = read_data($err_fh)) =~ s/[\r\n]{1,2}/\r\n/;
         ok t_cmp($value,
                  $output,
                  "testing subproc's stdin -> stderr + list context"
=========================================================================

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] apache/subprocess on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> Hi,
>    On Win32, the apache/subprocess tests fail on Win32.
> This is due to the following: currently, the tests do
> something like
> 
>    @argv = qw(potentially something);
>    $command = catfile $target_dir, "some_script.pl";
>    Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> 
> The problem on Win32 is that $command isn't associated with Perl.
> To fix this, one could do one of two things.
> 
> - create a "some_script.bat" with pl2bat, use
>    $command = catfile $target_dir, "some_script.bat";
> and insert a
>    $r->subprocess_env->set(PATH => $Config{bin});
> before invoking the script.
> 
> - use
>     $command = $Config{perlpath}; # or perhaps better $^X
>     @list = ("some_script.pl", @argv);
>     Apache::SubProcess::spawn_proc_prog($r, $command, \@list);
> (the potentially nicer looking
>     $command = "$Config{perlpath} some_script.pl";
>     Apache::SubProcess::spawn_proc_prog($r, $command, \@argv);
> doesn't work - I think it interprets $command as one single
> command - Win32 is famous for problems with quoting command-line
> things).
> 
> Either of the above works - does anyone have a strong
> preference one way or another?

I prefer 2nd, since it doesn't force us to modify the filename. However I'd 
check whether $Config{perlpath} works everywhere. Perhaps check perl test 
suite to see what it uses? I remember there was a discussion of may be using 
$^X. or both.

otherwise +1

> Incidentally, for both, subtests 3 and 4 need
> some massaging for line endings - either have
>    my $value = "some text\r\n";
> or use
>    $output =~ s!\r!!;
> Although, with perlio the :crlf filter would be
> available, which would be neater ...

what about mac? there is no \r there. I guess we need to do what CGI.pm does 
or is there a standard module that defines $CRLF?

In any case we could probably always write "\r\n" (e.g. "some text\r\n") and 
then after reading the output do:

s/[\r\n]{1,2}/\r\n/;

and only then compare. Will that work?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org