Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-30 Thread John Siracusa

On 6/30/02 2:06 AM, Stas Bekman wrote:
 John Siracusa wrote:
 (I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
 it to both lists.  Redirect follow-ups as appropriate.)
 
 open2() doesn't seem to work for me when running under mod_perl in Mac OS X.
 
 It's not a bug in MacOSX, it simply doesn't work with mod_perl.

I can't post a direct example now (because I don't have access to the
machine from here), but I'm pretty sure I do have an example of open2()
working under mod_perl in Linux--in a perl that is not compiled with sfio.
That's why I thought it was a Mac OS X bug.

The mod_perl guide talks about the output from system(), exec(), and open(F,
| ...) not being sent to the browser, but it doesn't mention open2().  In
the case of open2(), the input and output is supposed to be tied to
filehandles that I supply, not connected to mod_perl's (tied?) STDOUT that
eventually goes to the browser.

So could you clarify why open2() is not expected to work under mod_perl, and
why it seems to work for me in Linux?  (I'll post the working Linux example
once I can confirm it on Monday.)

-John




Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-30 Thread Stas Bekman

John Siracusa wrote:
 On 6/30/02 2:06 AM, Stas Bekman wrote:
 
John Siracusa wrote:

(I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
it to both lists.  Redirect follow-ups as appropriate.)

open2() doesn't seem to work for me when running under mod_perl in Mac OS X.

It's not a bug in MacOSX, it simply doesn't work with mod_perl.
 
 
 I can't post a direct example now (because I don't have access to the
 machine from here), but I'm pretty sure I do have an example of open2()
 working under mod_perl in Linux--in a perl that is not compiled with sfio.
 That's why I thought it was a Mac OS X bug.
 
 The mod_perl guide talks about the output from system(), exec(), and open(F,
 | ...) not being sent to the browser, but it doesn't mention open2().  In
 the case of open2(), the input and output is supposed to be tied to
 filehandles that I supply, not connected to mod_perl's (tied?) STDOUT that
 eventually goes to the browser.
 
 So could you clarify why open2() is not expected to work under mod_perl, and
 why it seems to work for me in Linux?  (I'll post the working Linux example
 once I can confirm it on Monday.)

I should have said that your example doesn't work on linux with mod_perl 
with sfio-enabled perl, since I've tried it and it didn't work. That's 
why I've assumed that it's not MacOSX problem.

I really didn't have a chance to investigate why it doesn't work. I've 
just tried other alternatives which worked so I've posted them, since I 
thought that it was important to you to have a working solution. Feel 
free to debug the whole thing and post the details of what exactly 
doesn't work and if possible how to fix that.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




Re: IPC::Open2 under mod_perl in Mac OS X

2002-06-29 Thread Stas Bekman

John Siracusa wrote:
 (I'm not sure if this is a mod_perl thing of a Mac OS X bug, so I'm posting
 it to both lists.  Redirect follow-ups as appropriate.)
 
 open2() doesn't seem to work for me when running under mod_perl in Mac OS X.

It's not a bug in MacOSX, it simply doesn't work with mod_perl. the 
piped program ('upcase' in your example) never sees any input. There are 
at least two working alternatives:

1) use IPC::Run:

#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use IPC::Run qw(start finish) ;

local $ENV{PATH};
print header();

my @cmd = qw(/tmp/upcase) ;
my $h = start \@cmd,
 'pipe', \*IN,
 'pipe', \*OUT,
 '2pipe', \*ERR
 or die @cmd returned $? ;
print IN Perl::Run and Barrie rule!;
close IN;
print OUT, ERR;
finish $h ;

the upcase program without any change:

 #!/usr/bin/perl
 $buf .= $_ while(STDIN);
 print uc $buf;

2) use Apache::SubProcess:

use Apache::SubProcess ();
my $r = shift;
$r-send_http_header('text/plain');

use vars qw($input);
$input = Apache::SubProcess rules too!;
my($out, $in, $err) = $r-spawn_child(\upcase);
print $out $input;
$r-send_fd($in);

sub upcase {
 my $r = shift;
 $r-subprocess_env(CONTENT_LENGTH = length $input);
 $r-filename(/tmp/upcase);
 $r-call_exec;
}

notice that the upcase script will be different from yours in this case, 
it looks like:

#!/usr/bin/perl
read STDIN, $buf, $ENV{CONTENT_LENGTH};
print uc $buf;

As this module lacks any docs, you can find them here:
http://perl.apache.org/release/docs/1.0/guide/modules.html#Apache__SubProcess

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com