![](/img/trans.png)
[英]Why does Windows API function createDirectoryW fail when used from a Perl script?
[英]Why does my Perl script halt if CGI module is used after reading from stdin on Windows?
我正在尝试为文件上传实现进度指示器。 如果分别执行,脚本的第1部分和第2部分将正常运行。 但是如果一起执行,脚本将在以下位置停止:
my $cg = new CGI();
仅在Windows服务器上会出现此问题。 可能是什么原因?
#!C:\Perl\bin\perl.exe -w use CGI; $post_data_filename = "C:\\test\\postdata.txt"; $uploaded_filename = "C:\\test\\uploaded_file.txt"; #PART 1 # read and store the raw post data in a temporary file so that we can repeatedly # look at size of this temporary file in order to implement a progress bar open(TMP,">","$post_data_filename"); $len = $ENV{'CONTENT_LENGTH'}; read (STDIN ,$LINE, $len); print TMP $LINE; close (TMP); #PART 2 #use a CGI instance to read the raw post data and extract the uploaded file from it my $cg = new CGI(); open(STDIN,"$post_data_filename"); my $fh = $cg->upload('file[0]'); open($tmp_fh, ">$uploaded_filename"); while(<$fh>) { print $tmp_fh $_; } close($tmp_fh); print "Content-type: text/html\n\n"; print "Ready\n"; exit;
尝试从中读取binmode(STDIN)。 我猜您最终得到的字节数少于内容长度所说的字节数,这导致CGI混乱。 重新打开STDIN之后,您可能还需要执行binmode。
另外,请检查所有IO操作是否成功。
在Windows上,无法打开文件进行读取,而在另一个进程中可以打开文件进行写入。
而且您的上传计量器将无法工作,因为您先读取了整个STDIN,然后将其写入TMP,所以您从0%直接变为100%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.