【发布时间】:2012-07-28 04:09:47
【问题描述】:
当我使用系统运行我的 perl 程序时,我收到以下错误。
> system("perl txt2xlsx.pl", intern=TRUE, wait=TRUE)
character(0)
attr(,"status")
[1] 2
Warning message:
running command 'perl txt2xlsx.pl' had status 2
但是,当我从终端/控制台运行脚本时,它工作得非常好。 出于测试目的,我将另一个仅在屏幕上打印“输出”的 perl 脚本放入同一目录并运行它:
> system("perl test.pl", intern=TRUE, wait=TRUE)
[1]“输出”
工作正常。
当您不带任何参数运行我的 txt2xlsx.pl 脚本时,它会打印:
Usage: txt2xlsx.pl <directory> <output file>
谁能想象为什么 R 会返回这个错误?在我更新到最新的 perl 版本之前它运行良好:
This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-multi-2level
干杯
这是我的一些 perl 脚本:
#!/usr/bin/perl
use Excel::Writer::XLSX;
# Check command line args
if($#ARGV != 1) {
die("Usage: $0 <directory> <output file>\n\n");
}
my $dir = $ARGV[0];
my $output = $ARGV[1];
print "Output : $output\n";
print "Directory : $dir\n";
# Create excel workbook
my $wb = Excel::Writer::XLSX->new($output);
# Process files
foreach (glob("$dir/*.txt")) {
....
}
#EOF
我做了一些更多的测试并减少了 perl 脚本以仅打印两个参数:
#!/usr/bin/perl
#use Excel::Writer::XLSX;
# Check command line args
if($#ARGV != 1) {
die("Usage: $0 <directory> <output file>\n\n");
}
my $dir = $ARGV[0];
my $output = $ARGV[1];
print "Output : $output\n";
print "Directory : $dir\n";
当我使用它的两个预期参数调用程序时系统工作:
> system("perl test.pl asd dasd", intern=TRUE, wait=TRUE)
[1] "Output : dasd" "Directory : asd"
没有它会产生相同的错误消息:
> system("perl test.pl", intern=TRUE, wait=TRUE)
character(0)
attr(,"status")
[1] 255
Warning message:
running command 'perl test.pl asd dasd' had status 255
当我评论 #use Excel::Writer::XLSX; 时,我注意到使用 system 的系统调用失败:
> system("perl test.pl asd dasd", intern=TRUE, wait=TRUE)
character(0)
attr(,"status")
[1] 2
Warning message:
running command 'perl test.pl asd dasd' had status 2
所以看起来它不喜欢 XLSX perl 模块。但是,正如我已经提到的,在终端中运行脚本绝对可以。而且它还可以在更新前与 R 系统调用一起使用...
--------
我正在使用 StatET 和 Eclipse,并尝试在普通 R 版本中运行它。那里的错误信息更加清晰。当我通过 R 调用 perl 调用时,perl 找不到代码中使用的 XLSX 包:
> system("perl test.pl asd asd", intern=TRUE, wait=TRUE)
character(0)
attr(,"status")
[1] 2
Warning message:
running command 'perl test.pl asd asd' had status 2
Can't locate Excel/Writer/XLSX.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-
thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-
2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4
/System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12
/System/Library/Perl/Extras/5.12/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.12 .) at test.pl line 3.
BEGIN failed--compilation aborted at test.pl line 3.
有人知道怎么解决吗?
【问题讨论】:
-
你能提供 tst2xlsx.pl 的代码吗?具体来说,当您不提供任何参数时,它会以什么形式退出?