HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
####
use strict;
use warnings;
my $cmd = 'perl -le "print qq{to stdout};print STDERR qq{to stderr};exit 42"';
my $cmdhack = qq{cmd /d/c $cmd 2>&1}; # works
# my $cmdhack = qq{cmd /d/c "$cmd" 2>&1}; # also works (despite bizarre quoting)
print "run:$cmdhack:\n";
my $out = `$cmdhack`;
my $rc = $? >> 8;
print "rc=$rc, stdout/stderr of command follows:\n";
print $out;
####
use strict;
use warnings;
my $outfile = 'ff.tmp';
my $exe = $^X;
my @args = ( 'perl', '-le', 'print qq{to stdout};print STDERR qq{to stderr};exit 42' );
print "run exe:$exe:args:@args:\n";
print STDERR "here we go to stderr\n";
open(SAVOUT, ">&STDOUT") or die "error: save original STDOUT: $!";
open(SAVERR, ">&STDERR") or die "error: save original STDERR: $!";
open(STDOUT, '>', $outfile) or die "error: create '$outfile': $!";
open(STDERR, '>&STDOUT') or die "error: redirect '$outfile': $!";
system { $exe } @args;
my $rc = $? >> 8;
open(STDOUT, ">&SAVOUT") or die "error: restore STDOUT: $!";
open(STDERR, ">&SAVERR") or die "error: restore STDERR: $!";
close(SAVERR) or die "error: close SAVERR: $!";
close(SAVOUT) or die "error: close SAVOUT: $!";
print "rc=$rc\n";
print STDERR "rc=$rc to STDERR\n";