【发布时间】:2019-02-01 19:46:19
【问题描述】:
我的 firefox 安装在 C:\Program Files\Mozilla Firefox。
我正在尝试像这样阅读 firefox 版本:
open (IN, "\"C:\\Program\ Files\\Mozilla\ Firefox\\firefox.exe\" --version|") or die "Couldn't fork - $!\n";
my $aarray = (IN);
print $fh "=========Array Content========> $aarray <====\n";
close(IN);
这是完美的工作。但是,当我将路径或命令放在变量中并尝试执行时,它会说“无法分叉”
my $ffox = 'C:\Program Files\Mozilla Firefox\firefox.exe';
$ffox =~ s/\\/\\\\/g; #Replacing single \ with double \\
$ffox =~ s/\ /\\ /g; # Adding escape character before space
chop($firefoxVer); # remove last \n chr.
$ffox =~ s/$/\\\"/g; # With the below two commands, massaging the command to become
$ffox =~ s/^/\\\"/g; # "C:\\Program\ Files\\Mozilla\Firefox\\firefox.exe\"
$firefoxVer = $ffox.' --version|'; # Adding "version|" to the above command
$firefoxVer =~ s/$/\"/g; # and make it look like:
$firefoxVer =~ s/^/\"/g; # "\"C:\\Program\ Files\\Mozilla\\Firefox\\firefox.exe\" --version|"
open (IN, $firefoxVer) or die "Couldn't fork - $!\n"; ==> Fails
【问题讨论】:
-
chomp 没有帮助。它没有执行命令并读取命令的输出流。
-
是试图只获取版本,还是试图创建一个以版本为文件名的文件句柄?