【问题标题】:Perl unable to write file on serverPerl 无法在服务器上写入文件
【发布时间】:2026-01-01 05:05:01
【问题描述】:

我有一个包含一些文本的文件 in.txt
我在 Windows 上使用 IIS 7 本地服务器。 isapiModule 在 perl 上运行良好。
当我通过浏览器运行这个 perl 代码时,它打印到浏览器只是打印行(不是数据)但不写入文件 out.txt 并且只是打开空文件 out.txt(即无法通过浏览器写入)。
我的 wwwroot 文件夹对所有用户具有完全控制访问权限。

html代码:

<html>
<body>

<form name="form1" action="perl.pl" method="post"
enctype="multipart/form-data">
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html> 

perl.pl:

open(file,"<in.txt");
@x=<file>;
open(OUT,">out.txt");
print"print to browser...";
print OUT"@x\n";#for printing to file
close file;
close OUT;

可能是什么原因和解决方法。

更新:程序在通过命令驱动器手动运行时正在写入。

【问题讨论】:

  • use strict; use warnings; 并测试是否打开失败。
  • @M42 错误:“脚本发送数据失败。”
  • 嗨,有更新吗?我也面临同样的问题。

标签: perl web iis-7


【解决方案1】:

你尝试过这样的事情吗?

#!/usr/bin/perl -w
use strict; 


my $in = 'in.txt';
open my $file, '<', $in or die "Can't open $in\n";

my $outfile = 'out.txt';
open my $outprint, '>', $outfile or die "Can't write to $outfile\n";


print "print to browser…\n";
while (<$file>) { 
    chomp;
    print $outprint "$_\n"; 
}

【讨论】:

  • 您好,它在命令行中运行良好,但在 IIS 中出现错误:“无法在.txt 中打开”。有什么解决办法吗?谢谢。