我有一个在 Win32 ActivePerl 上运行的 Perl/POE/Tk 脚本,它使用 system
调用可执行文件。我使用 pp
创建了该脚本的 exe。我可以解压 exe 并在“zip”文件目录的根目录中查看可执行文件,但是当我运行 exe 并尝试使用系统调用的功能时,我收到“文件未找到”类型的错误;
'..\cpau' is not recognized as an internal or external command,
operable program or batch file.
cpau.exe 是包含的文件之一。
pp
的调用方式如下:
pp -i alias3.ico -g -a add_event.job -a add_rec.job -a CPAU.exe -a del_event.job -a del_rec.job -a dnscmd.exe -a eventcreate.exe -o alias_v_3-0.exe alias_poe_V-3_0_par.pl
我猜测我需要调整系统
调用的路径。我目前正在尝试使用默认路径;
system("cpau -dec -file add_rec.job -nowarn -wait");
我尝试过这个:
system("..\cpau -dec -file ..\add_rec.job -nowarn -wait");
推断 pp 将脚本放在\scripts\目录中,但没有喜悦。有什么建议么?
最佳答案
更新:我的以下建议不起作用。但是,如果其他人有类似的问题,我将把它们保留下来。这个答案展示了很多听起来合理但行不通的事情。
请参阅discussion following the OP's repost代码 using $ENV{PAR_TEMP} 解决OP的问题
供引用
pp docs说:
-a, --addfile=FILE|DIR ...
block 引用>By default, files are placed under / inside the package with their original names.
通过使用系统,您正在询问
cmd.exe
找到该文件,我现在意识到这可能是一场失败的战斗,除非您有一个名为cpau.exe
的单独可执行文件。我现在没有时间尝试这个,但是您可能必须执行fork
和exec
自己而不是依赖system
。如:exec 'CPAU.exe', @args
上一个答案:
您传递给
system
的字符串不包含您认为的内容:use strict; use warnings; my $x= "..\cpau -dec -file ..\add_rec.job -nowarn -wait"; print $x, "\n"; __END__ C:\Temp> fgh ..►au -dec -file ..dd_rec.job -nowarn -wait
使用(根据下面的OP评论进行编辑):
system "..\\cpau -dec -file ../add_rec.job -nowarn -wait";
我还建议使用
system
的列表形式:system '..\\cpau', qw(-dec -file ../add_rec.job -nowarn -wait);
此外,您可能会发现 FindBin如果您想指定
cpau
的路径,很方便相对于当前脚本的目录。例如:
#!/usr/bin/perl use strict; use warnings; use FindBin qw($Bin); use File::Spec::Functions qw( catfile ); my $program = catfile $Bin, '..', 'cpau'; system $program, qw(-dec -file ../add_rec.job -nowarn -wait); __END__
关于perl - 为什么我的系统调用在我用 pp 包装的 Perl 程序中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1110546/