나는 perl 스크립트가있는 곳에서 여러 번 붙어 있습니다. CGI 파일에 쉘 스크립트를 실행하는 시스템 명령과 HTML 컨텐트가있는 함수를 만들었습니다. 그러면 CGI 함수를 호출하고 브라우저에 내용을 표시하는 perl 파일을 호출하는 href가 있습니다. 그러나 CGI에서 시스템 명령의 실행을 제외하고는 모든 것이로드됩니다. 필자는 Perl File 자체에이 시스템 명령을 넣으려고 시도했으며 명령 행에서 쉘 스크립트를 성공적으로 실행하고 있습니다. 그러나 이것은 버튼 클릭으로 발생하기를 원했기 때문에 CGI 호출을해야했지만 여전히 호출 할 수 없었습니다. 나는 많은 질문을했지만 나는 여전히 완벽한 답을 찾고있다. 다음은 내 코드입니다 : test1.plPerl에서 cgi를 통해 호출 할 때 시스템 명령이 실행되지 않습니다.
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Basecamp::UI;
use Basecamp::Dashboard;
use Basecamp::Info;
my $cgi = Basecamp::UI->new->cgi();
my $dashboard = Basecamp::Dashboard->new();
my @html = $cgi->tab_ext();
#push @html, '<div class="page">';
#push @html, newstuff();
#push @html, '</div>';
#print "Hello Hey";
#system(' sh /home/basecamplocal/Perforce/depot/qeutils/basecamp_dev/sample.sh ');
print $cgi->begin('Basecamp | ext', $dashboard), $cgi->begin_page();
print @html;
print $cgi->end_page(), $cgi->begin_footer(), $cgi->end_footer(), $cgi->end();
쉘 스크립트는 다음과 같습니다
#!/bin/bash
#perl Basecamp.pl > log_sample.txt
touch log_sample.txt
echo "Good Day"
CGI 파일 기능 :
=item tab_ext()
======================================================================================
DESC: Generates appropriate tabs for About, about.pl.
OUT: Returns array of scalars with html to draw the tabs and any associated
subtabs.
======================================================================================
=cut
sub tab_ext
{
my ($self) = @_;
my $tab = $self->param('tab');
my @tabs = ('<li><a href="test1.pl?tab=New">Status Restart</a></li>');
my @subtabs =();
my @html =();
$tabs[0] = '<li class="selected"><a href="#">Status Restart</a></li>';
@html = ('<ul id="tabs">', @tabs, '</ul>');
push @html, ('<ul id="subtabs">', @subtabs, '</ul>');
print "Content-type: text/html\n\n";
system("sh /full path to shell file /sample.sh ");
return @html;
}
와 나는에 test1.pl 파일을 호출하고 href call html. CGI의 전체 HTML 컨텐트가 쉘 스크립트의 실행을 제외하고 표시됩니다. 도움의 손길을 보내 주시면 감사하겠습니다.
http://perlmaven.com/running-external-programs-from-perl – Vir
을 볼 수 있습니까? 링크는 모두 시스템 명령에 관한 것이므로 독립적 실행에서 잘 실행되고 있다고 말했습니다. –
'sh'를 명시 적으로 호출 할 필요가 없습니다 (CGI 스크립트로 실행할 때 디폴트'$ PATH'에 없을 수도 있습니다). 'sample.sh'을 실행 가능하게 만들고'system ('/ full/path/to/sample.sh'); 지금처럼 후행 공백이 포함되지 않도록하십시오. – reinierpost