The elephant that's been mentioned only implicitly is 'doze-style quoting.'
Sorry, this illustration (which presents two ways of working with Win32) is a bit on the long side but here goes, anyway...
#!/usr/bin/perl
use strict;
use warnings;
use 5.018;
# #1107536
my $program="D:\\GnuWin32\\bin\\ls.exe";
print "$program\n";
runit ($program);
sub runit
{
system ("$program");
if ($? == -1) {
print "failed to execute: $!\n";
}
say "\n\t DEBUG: reached the end of sub runit at Ln23";
sleep 1;
}
say "\n Done with first sub, back in main. \n";
my $path = 'D:/GnuWin32/bin/';
my $pgm="ls.exe";
my $cmd ="$path" . "$pgm";
runit2 ($cmd);
sub runit2
{
say "\n\tEntering runit2\n";
sleep 3;
my ($cmd_in_sub) = @_;
say "\n\t DEBUG: $cmd_in_sub\n";
system ("$cmd_in_sub");
if ($?) {
print "failed to execute: $!\n";
}
}
say "\n Done with second sub ";
Execution:
D:\>D:\_Perl_\PMonks\1107536NON-GUI.pl d:\_wo
D:\GnuWin32\bin\ls.exe
.. TestFiles
Connexions tbos.css
CPM-ZCPR ViennaProtocol.txt
created_psp_files WinSHAetc
DEBUG: reached the end of sub runit at Ln23
Done with first sub, back in main.
Entering runit2
DEBUG: D:/GnuWin32/bin/ls.exe
... TestFiles
Connexions tbos.css
CPM-ZCPR ViennaProtocol.txt
created_psp_files WinSHAetc....
Done with second sub
D:\>
M$Win mistreats (file and/or dir)_names_with_spaces unless the whole Path/Program_name match is double-quoted.
NB: This also works to invoke a Windows GUI program, such as Chrome or Beyond Compare.
Updated: by removing extraneous code; adding note
|