Subject: | Proc-Background uses forward slash instead of backslash as separator on Win32 |
Date: | Thu, 24 Jun 2010 14:12:19 +0100 |
To: | <bug-Proc-Background [...] rt.cpan.org> |
From: | <duncan.loveday [...] bt.com> |
Hi,
I might have found a problem with the file separator used when expanding
the PATH on Win32 in the Proc-Background module.
Here's an example program being run on windows XP
C:\cygwin\home\803042764>type bug.pl
type bug.pl
use Proc::Background;
my $proc = Proc::Background->new("cmd /c echo XXX");
C:\cygwin\home\803042764>perl bug.pl
perl bug.pl
C:\cygwin\home\803042764>The syntax of the command is incorrect.
C:\cygwin\home\803042764>
C:\cygwin\home\803042764>
I did a bit of debugging and concluded that this was due to
inappropriate use of a forward slash below in method "_resolve_path".
foreach my $dir (split($is_windows ? ';' : ':',
$ENV{PATH})) {
next unless length $dir;
$dir = "$cwd/$dir" unless $dir =~ /$is_absolute_re/o;
my $p1 = "$dir/$command";
<------------------------------------------------------------ WRONG ON
WIN32 ?
foreach my $ext (@extensions) {
my $p2 = "$p1$ext";
Proposed fix
foreach my $dir (split($is_windows ? ';' : ':',
$ENV{PATH})) {
next unless length $dir;
$dir = "$cwd/$dir" unless $dir =~ /$is_absolute_re/o;
my $p1 = $is_windows ? "$dir\\$command" :
"$dir/$command";
foreach my $ext (@extensions) {
my $p2 = "$p1$ext";
if (-f $p2 and -x _) {
$path = $p2;
last;
}
}
Here's the test program running after applying the above change
C:\cygwin\home\803042764>perl bug.pl
perl bug.pl
C:\cygwin\home\803042764>XXX
C:\cygwin\home\803042764>
C:\cygwin\home\803042764>
Strangely, when the command is submitted to Win32::Process what's
actually being run is this
C:\cygwin\home\803042764>C:\WINDOWS\System32/cmd
C:\WINDOWS\System32/cmd /c echo XXX
C:\WINDOWS\System32/cmd C:\WINDOWS\System32/cmd /c echo XXX
The syntax of the command is incorrect.
because arg[0] is present both as the executable name and in the args
array. This looks odd but it does work for relative paths or absolute
paths as long as backslashes are used, see below. Perhaps the /cmd is
being interpreted as /c md.
C:\cygwin\home\803042764>C:\WINDOWS\System32\cmd
C:\WINDOWS\System32\cmd /c echo XXX
C:\WINDOWS\System32\cmd C:\WINDOWS\System32\cmd /c echo XXX
XXX
C:\cygwin\home\803042764>cmd cmd /c echo XXX
cmd cmd /c echo XXX
XXX
C:\cygwin\home\803042764>
Platform details: Windows XP SP 2
C:\cygwin\home\803042764>perl -V
perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED
-DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='12.00.8804', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-libpath:"C:\Perl\lib\CORE" -machine:x86'
libpth=\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl58.lib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf -libpath:"C:\Perl\lib\CORE" -machine:x86'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
PERL_IMPLICIT_SYS PERL_MALLOC_WRAP
PL_OP_SLAB_ALLOC USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_SITECUSTOMIZE
Locally applied patches:
ActivePerl Build 822 [280952]
Iin_load_module moved for compatibility with build 806
PerlEx support in CGI::Carp
Less verbose ExtUtils::Install and Pod::Find
Patch for CAN-2005-0448 from Debian with modifications
Rearrange @INC so that 'site' is searched before 'perl'
Partly reverted 24733 to preserve binary compatibility
MAINT31223 plus additional changes
31490 Problem bootstraping Win32CORE
31324 Fix DynaLoader::dl_findfile() to locate .so files again
31214 Win32::GetLastError fails when first called
31211 Restore Windows NT support
31188 Problem killing a pseudo-forked child on Win32
29732 ANSIfy the PATH environment variable on Windows
27527,29868 win32_async_check() can loop indefinitely
26970 Make Passive mode the default for Net::FTP
26379 Fix alarm() for Windows 2003
24699 ICMP_UNREACHABLE handling in Net::Ping
Built under MSWin32
Compiled at Jul 31 2007 19:34:48
@INC:
C:/perl/site/lib
C:/perl/lib
.
C:\cygwin\home\803042764>
Duncan.