Subject: | Process::Create() not searching PATH for partial executable name |
Date: | Tue, 26 Dec 2006 08:58:05 -0800 |
To: | bug-libwin32 [...] rt.cpan.org |
From: | Greg Ercolano <erco [...] 3dsite.com> |
[as reported on bugs.activestate.com, bug #65241]
ActivePerl 5.8.5 build 804 on Windows 2000 and Windows XP
[full output of 'perl -V' at end]
DESCRIPTION
-----------
It seems Win32::Process::Create() does not support WIN32 CreateProcess()'s
ability to set $appname to NULL (0), and set a partial name for $cmdline,
so that the full path to the executable need not be specified.
In C++, CreateProcess() can run an executable with a partial name
(ie. without a pathname or extension specified) if 'appname' is NULL, eg:
CreateProcess(NULL, // appname
"netstat -an", // commandline
NULL,
..)
..which works, as per Microsoft's docs for CreateProcess(), indicating
it searches the PATH when a partial name is specified.
In Perl's Process::Create(), the equivalent apparently doesn't work:
Win32::Process::Create($pobj,
0, # appname
"netstat -an", # commandline
1, # inherit handles
NORMAL_PRIORITY_CLASS, # etc..
".");
..this fails with "The system cannot find the file specified." I also
tried 'undef', "" and "0" for the "appname" field with same results.
This is hard to work around, without a brute force walk of the PATH's
components to seek out the absolute path to the executable, which can
be expensive and non-trivial, esp. when the PATH is large, and contains
network components.
SOLUTION
--------
It would be good if the perl Process::Create() worked consistently with
the Win32 equivalent, as often the absolute pathname to the executable is
not known to the script, such as when the executable is a third party app.
ATTEMPTED WORKAROUNDS
---------------------
I tried invoking cmd.exe with an absolute path, passing my command as
arguments to that, so that cmd.exe would do the search for the executable.
Trouble is, involving cmd.exe introduces a different problem where if the
cwd is a UNC path, cmd.exe prints a warning that UNC paths aren't supported (!)
and falls back to using C:\windows as the CWD before running my command,
fatal to some of my user's situations. :/
So avoiding calling cmd.exe is important, hence the approach of
trying to invoke my command with CreateProcess().
I also can't use system() because even though it tries to avoid
using cmd.exe, it has the problem with -1 exit codes
(reported as bug #60738 which was reattached to bug #45337).
So I'm kinda cornered into either writing a custom extension,
or trying to troubleshoot/repair the Win32::Create::Process() module.
OUTPUT OF 'perl -V'
-------------------
Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=undef 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 -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
optimize='-MD -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
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 -release -libpath:"C:\Perl\lib\CORE" -machine:x86'
libpth="C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Lib\" "C:\Perl\lib\CORE"
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 wsock32.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 wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version='undef'
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -libpath:"C:\Perl\lib\CORE" -machine:x86'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
Locally applied patches:
ActivePerl Build 804
Built under MSWin32
Compiled at Dec 1 2002 23:15:13
@INC:
C:/Perl/lib
C:/Perl/site/lib
.