In my (cmd.exe's) current working directory is a file named libre-office-document.odt. I can open this document using the start
command without problem:
c:\path\to\> start libre-office-document.odt
Yet, if I use the following simple Perl script
use warnings;
use strict;
print system("start libre-office-document.odt")
and execute it in the same directory, I get the following message box:
LibreOffice 4.4 - Fatal Error
The application cannot be started.
User installation could not be completed.
Obviously, something behaves differently when using Perl's system
command. I am unable to determine what that is and how I can open the document with the system
command.
Use backticks to capture output. You can check file associations with assoc and ftype, than hardcode it, or try this:
use strict;
use warnings;
my $assoc = `assoc .odt`;
# .odt=LibreOffice.WriterDocument.1
chomp $assoc;
$assoc =~ s/.*=//g;
my $ftype = `ftype $assoc`;
# LibreOffice.WriterDocument.1="C:\Program Files\LibreOffice\program\soffice.exe" -o "%1"
chomp $ftype;
$ftype =~ /.*=("[^"]*")/;
$ftype = $1;
# "C:\Program Files\LibreOffice\program\soffice.exe" libre-office-document.odt
my $cmd = "$ftype libre-office-document.odt";
system($cmd);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With