Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 如何在.cgi脚本中调用.pl文件_Perl_Pdf_Cgi_Perl Module - Fatal编程技术网

Perl 如何在.cgi脚本中调用.pl文件

Perl 如何在.cgi脚本中调用.pl文件,perl,pdf,cgi,perl-module,Perl,Pdf,Cgi,Perl Module,我使用CAM::PDF中的getpdftext.pl来提取PDF并将其打印为文本,但在我的web应用程序中,我想在.cgi脚本中调用这个getpdftext.pl。你能建议我做什么或如何继续前进吗。我尝试将getpdftext.pl转换为getpdftext.cgi,但不起作用 谢谢大家 这是我的request_admin.cgi脚本的摘录 my $filename = $q->param('quote'); : : : &parsePdf($filename); #funct

我使用CAM::PDF中的getpdftext.pl来提取PDF并将其打印为文本,但在我的web应用程序中,我想在.cgi脚本中调用这个getpdftext.pl。你能建议我做什么或如何继续前进吗。我尝试将getpdftext.pl转换为getpdftext.cgi,但不起作用

谢谢大家

这是我的request_admin.cgi脚本的摘录

my $filename  = $q->param('quote');
:
:
:
&parsePdf($filename);

#function to extract text from pdf ,save it in a text file and parse the required fields
sub parsePdf($)
{
    my $i;
    print $_[0];
    $filein = "quote_uploads/$_[0]";
    $fileout = 'output.txt';

    print "inside parsePdf\n";

    open OUT, ">$fileout" or die "error: $!";

    open IN, '-|', "getpdftext.pl $filein" or die "error :$!" ;

    while(<IN>)
    {
        print "$i";
        $i++;
        print OUT;
    }

}
my$filename=$q->param('quote');
:
:
:
&parsePdf($filename);
#函数从pdf中提取文本,将其保存在文本文件中并解析所需字段
sub-parsePdf($)
{
我的$i;
打印美元[0];
$filein=“quote_uploads/$\u[0]”;
$fileout='output.txt';
打印“内部解析PDF\n”;
打开“>$fileout”或死亡“错误:$!”;
在“-|”中打开,“getpdftext.pl$filein”或在“error:$!”中死亡;
while()
{
打印“$i”;
$i++;
打印输出;
}
}

很可能

  • 您的CGI脚本的环境不够完整,无法定位
    getpdftext.pl
    和/或
  • web服务器用户无论如何都没有执行它的权限

查看您的web服务器的错误日志,看看它是否报告了任何关于此错误原因的指针。

在您的特定情况下,直接使用它可能更简单、更直接,无论如何,它应该与
getpdftext.pl
一起安装

我看过这个脚本,我认为您的
parsePdf
子脚本可以很容易地编写为:

#!/usr/bin/perl
use warnings;
use strict;

use CAM::PDF;

sub parsePdf {
    my $filein = "quote_uploads/$_[0]";
    my $fileout = 'output.txt';

    open my $out_fh, ">$fileout" or die "error: $!";

    my $doc = CAM::PDF->new($filein) || die "$CAM::PDF::errstr\n";
    my $i = 0;

    foreach my $p ($doc->rangeToArray(1,$doc->numPages()))
    {
        my $str = $doc->getPageText($p);
        if (defined $str)
        {
            CAM::PDF->asciify(\$str);
            print $i++;
            print $out_fh $str;
        }
    }
}

您的意思是在“-”中打开“
”、“perl getpdftext.pl$filein”还是死“error:$!”?是的,杰克..我指的是“perl getdpftext.pl$filein”,我得到以下错误:在/request_admin.cgi第301行,第414行,referer第301行:open OUT,“>$fileout”或die“error:$!”;在这种情况下,您需要允许web服务器访问该文件。非常感谢,vl尝试这种方式,在我的程序中发现错误,但无法调试,它在
open OUT,“>$fileout”或die“error:$!”
@sandyutd:尝试在当前目录中写入$fileout时存在权限问题。将$fileout更改为
$ENV{TEMPDIR}/output.txt
,尽管这也不太好——它肯定不支持并发请求——但至少可以让您向前迈进。最后,您需要确保每个请求都使用自己独特的临时文件,即
$ENV{TEMPDIR}/output-$$.txt
($$相当于CGI进程的PID)。@sandyutd-如果合适,您还可以将调试输出写入STDERR,然后在apache日志中多次查看,错误出现在
open OUT,“>$fileout”或die中“错误:$!“;
getting Permission denied error,该文件存在,首先我应该做什么,确保getpdftext.pl脚本可由任何人执行,然后更改CGI脚本以使用其完整的绝对路径调用它