develooper Front page | perl.perl5.porters | Postings from May 2003

[PATCH] Use "cmd.exe /x/d/c" as the default PERL5SHELL on Windows NT/2K/XP

Thread Next
Jan Dubois
May 26, 2003 23:34
[PATCH] Use "cmd.exe /x/d/c" as the default PERL5SHELL on Windows NT/2K/XP
Message ID:
I was surprised to see that subprocesses started by Perl may end up
with a different working directory than the parent process.  This can
happen on Windows 2000 and later if the user specifies an "AutoRun"
command for cmd.exe that changes the current directory:

Perl only uses cmd.exe when the command contains shell metacharacters
or when the direct invocation failed (it may be a cmd.exe internal
command).  Therefore I think we should not execute the AutoRun commands
at all.  cmd.exe provides the "/d" option to disable them.  I have
verified that cmd.exe on Windows NT silently ignores this switch
(AutoRun was only added in Windows 2000).  On Windows 95/98/Me we
are using instead of cmd.exe, so it is not an issue there.

I would therefore suggest that we add the "/d" switch to cmd.exe


The following diff is against the snapshot perl@19613.tgz, even though
that particular snapshot doesn't compile with MS VC++ on Win32.

--- pod/perlrun.orig	Mon May 26 21:29:08 2003
+++ pod/perlrun.pod	Mon May 26 23:20:06 2003
@@ -1061,7 +1061,7 @@
 =item PERL5SHELL (specific to the Win32 port)
 May be set to an alternative shell that perl must use internally for
-executing "backtick" commands or system().  Default is C<cmd.exe /x/c>
+executing "backtick" commands or system().  Default is C<cmd.exe /x/d/c>
 on WindowsNT and C< /c> on Windows95.  The value is considered
 to be space-separated.  Precede any character that needs to be protected
 (like a space or backslash) with a backslash.

--- win32/Win32.orig	Mon May 26 21:29:11 2003
+++ win32/win32.c	Mon May 26 23:19:34 2003
@@ -506,7 +506,7 @@
 	 *     for).
 	const char* defaultshell = (IsWinNT()
-				    ? "cmd.exe /x/c" : " /c");
+				    ? "cmd.exe /x/d/c" : " /c");
 	const char *usershell = PerlEnv_getenv("PERL5SHELL");
 	w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About