如何使用Cygwin在perl脚本中运行系统命令

问题描述:

我试图在Cygwin中实现perl脚本。该脚本在内部进行了一些不同的调用。例如,如何使用Cygwin在perl脚本中运行系统命令

system "C:\\users\\program.exe"; 

exec("C:\\users\\program.exe"); 

当我尝试在Cygwin中运行它,它给我的错误:

sh: C:cygwin64cygdriveprogram.exe: command not found 

我知道这是一个愚蠢的问题,而是如何我可以找到program.exe?如果我通过cygwin终端中的目录,然后program.exe显然是...

一旦我找到了程序,我想在新的cygwin终端中产生新的进程。

使用UNIX文件分隔符和/cygdrive/c/虚拟驱动器:

system "/cygdrive/c/users/program.exe"; 

exec("/cygdrive/c/users/program.exe") 

exec("C:\\users\\program.exe"); 

执行的Bourne shell命令

C:\users\program.exe 

是编写

C:usersprogram.exe 

执行下面的shell命令可能工作的一个奇怪的方式:

C:\\users\\program.exe   # exec("C:\\\\users\\\\program.exe"); 

但正确的路径是

/cygdrive/c/users/program.exe # exec("/cygdrive/c/users/program.exe") 

TMTOWTDI:

#! /usr/bin/env perl 

use strict; 
use warnings; 

my @cmd = ("/c", "echo", "hi"); 

system('C:\\Windows\\System32\\cmd.exe',  @cmd) == 0 or die; 
system('C:/Windows/System32/cmd.exe',   @cmd) == 0 or die; 
system('/cygdrive/c/Windows/System32/cmd.exe', @cmd) == 0 or die; 

chomp(my $cmd = `cygpath 'C:\\Windows\\System32\\cmd.exe'`); 
system($cmd, @cmd) == 0 or die;