My firefox is installed in the location: C:\Program Files\Mozilla Firefox. Am trying to read the firefox version like this:
open (IN, "\"C:\\Program\ Files\\Mozilla\ Firefox\\firefox.exe\" --ver +sion|") or die "Couldn't fork - $!\n"; my $aarray = <IN>; print $fh "=========Array Content========> $aarray <====\n"; close(IN);
This is working perfectly. But, when I put path or command in a variable and try to execute, it fails saying "Couldn't fork"
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 comm +and to become $ffox =~ s/^/\\\"/g; # "C:\\Program\ Files\\Mozilla\ Firefox\\firefox. +exe\" $firefoxVer = $ffox.' --version|'; # Adding "version|" to the above co +mmand $firefoxVer =~ s/$/\"/g; # and make it look like: $firefoxVer =~ s/^/\"/g; # "\"C:\\Program\ Files\\Mozilla\ Firefox\\f +irefox.exe\" --version|" open (IN, $firefoxVer) or die "Couldn't fork - $!\n"; ==> Fails
The $firefoxVer variable contains "\"C:\\Program\ Files\\Mozilla\ Firefox\\firefox.exe\" --version|". When the entire command goes into the open command as hardcoded string, it works. But, when it is sent as $firefoxVer, it fails. Please help. Thanks.
In reply to Execute command with spaces in perl by naveenp5
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |