我的平面文本文件的路径是否错误?从 Linux 到 Windows 服务器

发布于 2024-10-30 05:16:13 字数 5293 浏览 1 评论 0原文

我是 Perl 新手。我正在尝试根据前人的工作和书籍进行学习,例如 学习 Perl现代 Perl。我正在尝试更新此脚本,该脚本解释 HTML 表单中的数据并将其写入文本文件,因为我们的实验室有兴趣重新启动并运行该脚本。最初的脚本是为在 Linux 服务器上使用而编写的,但我们已经从 Linux 切换到 Windows 服务器。

我没有管理员访问权限来查看错误消息的服务器是带有 ActivePerl 的 Windows 服务器。我很难找出 Windows 等效路径来告诉 Perl 脚本在哪里写入信息。从与管理员的交谈看来,我们的 Intranet 似乎映射到 E: 驱动器上,尽管这可能不是致命错误。

当我在表单中输入数据后尝试在浏览器中运行此脚本时,它只会返回一个通用信息:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

任何提示、文档、教程都将受到赞赏。谢谢。

#!C:\perl\bin\perl.exe -w -t

# Good programming practice dictates...
use strict;
use warnings;

# CGI.pm -- makes life easy
#Carp qw(fatalsToBrowser); outputs the error messages to the browser since there is no terminal to output error messages to. Should be removed before script is used in production.
use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";

# Initialize the CGI Interface
my($cgi) = new CGI;

# Print the Header
print $cgi->header();

#The dbmopen call is now de-appreciated. IE: it no longer works
#Kept for archival reasons
#if (! dbmopen(%DB, "/vol/research/docs/old_site_files/eyesignup/data/eyesignup_NEW.dat", 0666))
#   {
#   print "Error -- Cannot open database.\n";
#   exit;
#   }
# Tie is the correct way to do it now. But first we are going to experiment with writing to a flat .txt file.
open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";



# Store variables and increment access count for this user
# So param('VARIABLE') is the name of the variables used in the HTML form while $custVARIABLE is the input for the database

my($custFirst) = $cgi->param('firstname');
my($custLast) = $cgi->param('lastname');
my($custGender) = $cgi->param('gender');
my($custAge) = $cgi->param('age');
my($custDiv) = $cgi->param('division');
my($custPhone) = $cgi->param('phone');
my($custEmail) = $cgi->param('email');
my($custEmployee) = $cgi->param('employee');
my($custInternet) = $cgi->param('internet');
my($custwww) = $cgi->param('www');
my($custDemographic) = $cgi->param('demographic');
my($custProjects) = $cgi->param('projectsworked');
my($custExperience) = $cgi->param('experience');
my($custWeekdays) = $cgi->param('Weekdays');

#Kept for archival reasons
#my($custName) = $cgi->param('name');
#my($custGender) = $cgi->param('gender');
#my($custDiv) = $cgi->param('division');
#my($custPhone) = $cgi->param('phone');
#my($custEmail) = $cgi->param('email');
#my($custInternet) = $cgi->param('internet');
#my($custwww) = $cgi->param('www');
#my($custDemographic) = $cgi->param('demographic');
#my($custExperience) = $cgi->param('experience');
#my($custTimes) = $cgi->param('times');
#my($custStudies) = $cgi->param('studies');
#$custTimes =~ s/\r\n/~/g;

#This takes the input and places it into an array, starting with the individual's
@InfoDB = $custFirst."|".$custLast."|".$custGender."|".$custAge."|".$custDiv."|".$custPhone."|".$custEmail."|".$custEmployee."|".$custInternet."|".$custwww."|".$custDemographic."|".$custProjects."|".$custExperience."|".$custWeekdays;
print Datastore (@InfoDB);
print "\n";

#Kept for archivival reasons.
#$DB{$custName} = $custGender."|".$custDiv."|".$custPhone."|".$custEmail."|".$custInternet."|".$custwww."|".$custDemographic."|".$custExperience."|".$custTimes."|".$custStudies;

#Kept for archival reasons. dbmclose is de-appreciated
#dbmclose(%DB);
#Instead use untie. But first we're just going experiment with using a flat storage system.
#untie(%DB);
close (Datastore) or die;

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet.
print "Content-type: text/html\n\n";

print "<HTML>
<HEAD>
<TITLE>Thank you!</TITLE>
</HEAD>
<BODY>";

print "<H1><U>Thank You ".$custFirst."\!</U></H1>
<P>We appreciate your assistance.</P>
<HR width=\"75%\">";

print "<P><H3>The following information has been recorded:</H3>
Name: <I>".$custFirst."</I></p><P>
Gender: <i>".$custGender."</i></p><p>
Division: <i>".$custDiv."</i></p><p>
Phone: <i>".$custPhone."</i></p><p>
Email: <i>".$custEmail."</I></p><P>
How often do you use the internet?: <i>".$custInternet."</i></p><p>
How often do you visit the website?: <i>".$custwww."</i></p><p>
Are you familiar with demographic data?: <i>".$custDemographic."</i></p><p>
Do you have work experience in economics, business, or a related field?: <i>".$custExperience."</i></p><p>
Weekdays that you are available: <i>".$custWeekdays."</i></p><p>
";

print "
</BODY>
</HTML>";

我做了一些更改来弥补我正在工作的一些限制。例如,暂时将错误输出到浏览器,直到我开始工作。并从旧的 dbmopen 调用(不再有效)转移到平面文件贮存。

I'm a Perl newbie. I'm trying to learn based on a previous person's work and books such as Learning Perl and Modern Perl. I'm trying to update this script that interprets data from a HTML form and writes it into a text file since there is interest in our lab in getting this up and running again. The original script was written for use on a Linux server but we've since switched from Linux to Windows server.

The server that I do not have admin access to see the error messages is a Windows server with ActivePerl. I'm having difficulty figuring out the Windows equivalent path to tell the Perl script where to write the information. From talking to the admin it seems that our intranet is mapped on the E: drive, although this may not be the fatal error.

When I attempt to run this script in the browser after the data has been entered on a form it just returns a generic:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

Any tips, documentation, tutorials are appreciated. Thank you.

#!C:\perl\bin\perl.exe -w -t

# Good programming practice dictates...
use strict;
use warnings;

# CGI.pm -- makes life easy
#Carp qw(fatalsToBrowser); outputs the error messages to the browser since there is no terminal to output error messages to. Should be removed before script is used in production.
use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";

# Initialize the CGI Interface
my($cgi) = new CGI;

# Print the Header
print $cgi->header();

#The dbmopen call is now de-appreciated. IE: it no longer works
#Kept for archival reasons
#if (! dbmopen(%DB, "/vol/research/docs/old_site_files/eyesignup/data/eyesignup_NEW.dat", 0666))
#   {
#   print "Error -- Cannot open database.\n";
#   exit;
#   }
# Tie is the correct way to do it now. But first we are going to experiment with writing to a flat .txt file.
open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";



# Store variables and increment access count for this user
# So param('VARIABLE') is the name of the variables used in the HTML form while $custVARIABLE is the input for the database

my($custFirst) = $cgi->param('firstname');
my($custLast) = $cgi->param('lastname');
my($custGender) = $cgi->param('gender');
my($custAge) = $cgi->param('age');
my($custDiv) = $cgi->param('division');
my($custPhone) = $cgi->param('phone');
my($custEmail) = $cgi->param('email');
my($custEmployee) = $cgi->param('employee');
my($custInternet) = $cgi->param('internet');
my($custwww) = $cgi->param('www');
my($custDemographic) = $cgi->param('demographic');
my($custProjects) = $cgi->param('projectsworked');
my($custExperience) = $cgi->param('experience');
my($custWeekdays) = $cgi->param('Weekdays');

#Kept for archival reasons
#my($custName) = $cgi->param('name');
#my($custGender) = $cgi->param('gender');
#my($custDiv) = $cgi->param('division');
#my($custPhone) = $cgi->param('phone');
#my($custEmail) = $cgi->param('email');
#my($custInternet) = $cgi->param('internet');
#my($custwww) = $cgi->param('www');
#my($custDemographic) = $cgi->param('demographic');
#my($custExperience) = $cgi->param('experience');
#my($custTimes) = $cgi->param('times');
#my($custStudies) = $cgi->param('studies');
#$custTimes =~ s/\r\n/~/g;

#This takes the input and places it into an array, starting with the individual's
@InfoDB = $custFirst."|".$custLast."|".$custGender."|".$custAge."|".$custDiv."|".$custPhone."|".$custEmail."|".$custEmployee."|".$custInternet."|".$custwww."|".$custDemographic."|".$custProjects."|".$custExperience."|".$custWeekdays;
print Datastore (@InfoDB);
print "\n";

#Kept for archivival reasons.
#$DB{$custName} = $custGender."|".$custDiv."|".$custPhone."|".$custEmail."|".$custInternet."|".$custwww."|".$custDemographic."|".$custExperience."|".$custTimes."|".$custStudies;

#Kept for archival reasons. dbmclose is de-appreciated
#dbmclose(%DB);
#Instead use untie. But first we're just going experiment with using a flat storage system.
#untie(%DB);
close (Datastore) or die;

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet.
print "Content-type: text/html\n\n";

print "<HTML>
<HEAD>
<TITLE>Thank you!</TITLE>
</HEAD>
<BODY>";

print "<H1><U>Thank You ".$custFirst."\!</U></H1>
<P>We appreciate your assistance.</P>
<HR width=\"75%\">";

print "<P><H3>The following information has been recorded:</H3>
Name: <I>".$custFirst."</I></p><P>
Gender: <i>".$custGender."</i></p><p>
Division: <i>".$custDiv."</i></p><p>
Phone: <i>".$custPhone."</i></p><p>
Email: <i>".$custEmail."</I></p><P>
How often do you use the internet?: <i>".$custInternet."</i></p><p>
How often do you visit the website?: <i>".$custwww."</i></p><p>
Are you familiar with demographic data?: <i>".$custDemographic."</i></p><p>
Do you have work experience in economics, business, or a related field?: <i>".$custExperience."</i></p><p>
Weekdays that you are available: <i>".$custWeekdays."</i></p><p>
";

print "
</BODY>
</HTML>";

I've made a few changes to compensate for some of the limitations I am working in. For example, temporarily outputting errors to the browser until I get this working. And moving from the old dbmopen call (which is no longer working) to a flat file storage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烟燃烟灭 2024-11-06 05:16:13

使用 CGI::Carp qw(fatalsToBrowser) 或死“加载 CGI.pm 时出现问题”; 是你的问题。

$ perl -wle 'use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";'
syntax error at -e line 1, near "qw(fatalsToBrowser) or"
Execution of -e aborted due to compilation errors.

你的程序在编译时就快要死了,所以你没有得到有用的语法错误。通常您可以在日志中看到这一点,但您看不到。 use 语句中的 or die 是不必要的(并且是语法错误)。它已经会抛出错误。

在工作中,您确实非常需要在本地计算机上安装 Perl 副本来测试您的程序。用这个作为弹药。如果他们仍然不让您拥有工作工具,请使用便携式版本的 Strawberry Perl没有安装程序。

您还需要访问错误日志。向管理员询问这一点。他们可能只允许您访问您的日志,而不授予您对服务器的完全访问权限。

use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm"; is your problem.

$ perl -wle 'use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";'
syntax error at -e line 1, near "qw(fatalsToBrowser) or"
Execution of -e aborted due to compilation errors.

Your program was dying as it was compiling, so you got no useful syntax error. Normally you'd be able to see this in your logs, but you can't. The or die is unnecessary (and a syntax error) on a use statement. It will already throw an error.

You really, really need a copy of Perl on your local machine at work to test your programs. Use this as ammunition. If they still won't let you have the tools to work, use the portable version of Strawberry Perl that requires no installer.

You also need access to your error logs. Ask the admins for that. It's possible they can give you access to just your logs without giving you full access to the server.

千纸鹤 2024-11-06 05:16:13

您有以下几行:

# Print the Header
print $cgi->header();

以及更下面的几行:

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet. 
print "Content-type: text/html\n\n";

两者都执行相同的操作 - 您将相同的内容类型标头打印两次。您可以删除一个或另一个 print 调用。另请快速浏览一下 CGI 中对 header() 的引用。 pm docs 查看您可以执行的其他操作。

You have the following lines:

# Print the Header
print $cgi->header();

and further down:

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet. 
print "Content-type: text/html\n\n";

Both do the same thing — you are printing the same content-type header twice. You might remove one or the other print call. Also take a quick look through references to header() in the CGI.pm docs to see the other things you can do.

烟酉 2024-11-06 05:16:13

另外,作为一个粗略的尝试:

open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";

我不是 Windows 人员,但我认为 Windows 中的路径名使用 反斜杠,而不是几乎其他人都选择使用的正斜杠。

除了修复 print 调用之外,您还可以将路径名替换为:

E:\intranet\sds\research\docs\data.txt

Also, as a rough stab in the dark:

open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";

I'm not a Windows guy, but I think pathnames in Windows use backslashes, instead of the forward slashes that pretty much everyone else settled on using.

In addition to fixing the print call, you might also replace the pathname with:

E:\intranet\sds\research\docs\data.txt
晨光如昨 2024-11-06 05:16:13

另一项建议可能与该问题无关,而只是一个冗余问题:

#!C:\perl\bin\perl.exe -w -t

-w 标志与以下内容相同:

use warnings;

One other suggestion that probably doesn't have anything to do with the issue, but is just a matter of redundancy:

#!C:\perl\bin\perl.exe -w -t

The -w flag is the same thing as:

use warnings;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文