2013-04-25 3 views
2
%use IPC::Run3; 
%my $a; 
%run3 ['echo','hello'],\undef,\$a; 
<% $a %> 

mason 코드는 HTML::Mason::Admin에서 설명한대로 독립 실행 형 스크립트에서 Mason을 사용할 때 매우 잘 작동합니다. 죄송합니다. perl_mode으로 실행하면 $a빈 문자열입니다. 아래는 내IPC :: Run3이 Apache 환경에서 표준 출력을 캡처 할 수없는 이유는 무엇입니까?

Alias /mason_book /home/charlse/f/books/mason_book 
<Location /mason_book> 
    SetHandler perl-script 
    AddHandler perl-script .mas 
    PerlHandler HTML::Mason::ApacheHandler 
    PerlAddVar MasonCompRoot "mason_book => /home/charles/f/books/mason_book" 
</Location> 
<Directory "/home/chunywan/f/books/mason_book"> 
    Options Indexes FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory> 

httpd.conf BTW

%use IPC::Run qw(run timeout); 
%my @cmd=qw(echo hello world); 
%my ($in,$out,$err); 
%run(\@cmd, \$in, \$out, \$err) or die "cat: $?"; 
<pre> 
    out <% $out %> 
</pre> 

난 그냥 독립형 모드와 mod_perl 모드 모두에서 아주 잘 작동 IPC::Run을 시도합니다. IPC::Run3 대신 IPC::Run을 사용하기 위해 모든 소스 코드를 업데이트해야하는 것으로 보입니다.

+0

을 반환? – ikegami

+0

@ikegami,'PerlSetEnv IPCRUN3DEBUG 1'을 활성화 시켰습니다. 오류 로그는 run3이 명령을 올바르게 실행하고'$? '가 0임을 보여줍니다. – wcy

답변

2

나는 해결책이 일시적으로 STDIN/STDOUT을 열고 명령을 마친 후에 닫는 것이 해결책이라고 생각합니다.

use IPC::Run3; 
my $a; 

#save off existing stdin/out 
my ($save_stdin,$save_stdout); 
open $save_stdin, '>&STDIN'; 
open $save_stdout, '>&STDOUT'; 

#open it again as the "normal things" 
open STDIN, '>&=0'; 
open STDOUT, '>&=1'; 
run3 ['echo','hello'],\undef,\$a; 

#clean up after yourself 
close(STDIN); 
close(STDOUT); 
open STDIN, '>&', $save_stdin; 
open STDOUT, '>&', $save_stdout; 

나는 IPC :: 된 Open3와 같은 문제로 실행하고 여기에 그것을 해결 : 어떤 오류 https://stackoverflow.com/a/24311232/312208