Perl:使用 cygwin perl 运行 perl 脚本时找不到启动命令 (Windows)

PPP*_*PPP 2 windows perl cygwin

下面是setup.pl的代码:

my  $fileToCopy= "ewq_file.bat";
my $destination = $ENV{PREPARE};   ### $destination = C:\Windows
if ( -f "$destination\\$fileToCopy" ) {
    print "Triggering $destination\\$fileToCopy\n";
    system("start $destination\\$fileToCopy"); 
}
Run Code Online (Sandbox Code Playgroud)

触发时:C:\cygwin\bin\perl.exe setup.pl

输出:

Triggering C:\Windows\ewq_file.bat
sh: start: command not found
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

ike*_*ami 5

您正在 unix 模拟环境中使用 Perl 的 unix 版本。除非你另有说明,否则system使用。sh但它start是一个cmd内置的。

system( "cmd", "/c", "start", "", "$destination\\$fileToCopy" );

die( "Can't launch shell: $!\n"                   ) if $? == -1;
die( "Child killed by signal ".( $? & 0x7F )."\n" ) if $? & 0x7F;
die( "Child exited with error ".( $? >> 8 )."\n"  ) if $? >> 8;
Run Code Online (Sandbox Code Playgroud)