Code: Select all
use strict;
use warnings;
use Win32::Process;
my($exe, $cmd);
$exe = q{C:\windows\system32\cmd.exe};
# Phase 7.3 says, "If in command line mode and the command is not quoted and
# does not begin with a volume specification, white-space, `,`, `;`, `=` or `+`
# then break the command token at the first occurrence of `<space>` `,` `;` or
# `=` ..."
$cmd = <<\_EOF;
:: Quoted FAILS: no way to suppress percent expansion (Phase 1)
/c ""c:\subdir\foo %Path%bar.bat""
:: Unquoted w/ volume specification WORKS.
/c "c:\subdir\foo^ ^%Path^%bar.bat"
:: Unquoted w/ UNC, w/o special first byte FAILS: Phase 7 breaks token
/c "\\localhost\c$\subdir\foo^ ^%Path^%bar.bat"
:: Unquoted w/ UNC, w/ special first byte FAILS: first byte corrupts UNC path
/c "^ \\localhost\c$\subdir\foo^ ^%Path^%bar.bat"
_EOF
chomp $cmd;
STDOUT->autoflush;
foreach my $c (split /\n/, $cmd) {
next if $c =~ /^$/ or $c =~ /^::/;
print "==== $c\n";
Win32::Process::Create(my $p, $exe, $c, 1, 0, ".");
$p->Wait(INFINITE) || die;
print "\n";
}