jlongino has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone please explain why it is that the following program will run as expected:
use strict; use Win32::Process; use Win32; Win32::Process::Create($Win32::Process::Create::ProcessObj, "/my files/jim/perl monks/tkwarn.exe", # path to executable '', # command line args 0, # Don't inherit stuff DETACHED_PROCESS, # flags for creation "C:/my files/jim/perl monks") or # current dir. die print_error(); sub print_error() { return Win32::FormatMessage( Win32::GetLastError() ); }
Yet, if I make a slight change:
"C:/my files/jim/perl monks/tkwarn.exe", # path to executable
I get the error message:
The system cannot find the file specified.
Now ordinarily I wouldn't think this was so strange, except the Perl Cookbook has the example:
# loader - starts Perl scripts without the annoying DOS window use strict; use Win32; use Win32::Process; # Create the process object. Win32::Process::Create($Win32::Process::Create::ProcessObj, 'C:/perl5/bin/perl.exe', # Whereabouts of Perl 'perl realprogram', # 0, # Don't inherit. DETACHED_PROCESS, # ".") or # current dir. die print_error(); sub print_error() { return Win32::FormatMessage( Win32::GetLastError() ); }
I wondered if the "current dir" path I gave would cause a similar problem so I gave an invalid directory for "current dir" and received an error message:
The directory name is invalid.
So . . . it likes "C:" in the current dir spec, but not in the executable file spec? If anyone could help me to understand this I would be most grateful.

"It is much more comfortable to be mad and know it, than to be sane and have one's doubts." -- G. B. Burgin

Replies are listed 'Best First'.
Re: No useful device on path to madness
by Zaxo (Archbishop) on Sep 29, 2001 at 10:10 UTC

    I'm not au courant on win32 perl, but the difference between

    use Win32::Process; use Win32;
    and
    use Win32; use Win32::Process;
    is that the second case can find both Win32 and Win32::Process methods, while the first only finds Win32:: stuff without explicit localization by namespace.

    After Compline,
    Zaxo

      Thanks for pointing that out, it's interesting that I cut the bad code out of perldoc Win32::Process. The Perl Cookbook had it right.

      Unfortunately, changing it didn't fix my problem. I also replaced "/my files/jim/perl monks/" with "/myfile~1/jim/perlmo~1/". Both work as long as I don't add the "C:".

      "Show me a sane man and I will cure him for you." -- Carl Gustav Jung

Re: No useful device on path to madness
by jlongino (Parson) on Sep 30, 2001 at 00:18 UTC
    Okay, I've defined the problem and found solutions (could've sworn I tried every possibility last night). Apparently, it simply will not work with forward slashes (/) and a drive spec (C:).

    It does however work with backslashes (\):

    'c:\path1\path2\file.exe'
    or
    "c:\\path1\\path2\\file.exe"
    Also, case of the drive letter doesn't seem to matter. Thanks to everyone who responded. I would definitely call this a bug (at least with Win98 2ed/ASP 5.6.1).
Re: No useful device on path to madness
by C-Keen (Monk) on Sep 29, 2001 at 13:25 UTC
    I am no expert on Windows systems, but try running the script with the absolute path single quoted so the string is not evaluated. Maybe this helps. I do not hae acces to a windows box so this is just a guess but maybe worth trying.

    Regards,
    C-Keen

      Thanks for trying. But single/double quotes don't seem to make a difference.

      "Make everything as simple as possible, but not simpler." -- Albert Einstein

Re: No useful device on path to madness
by rchiav (Deacon) on Sep 29, 2001 at 22:13 UTC
    I don't have a specific answer but I can tell you what I've done that's worked. What I notice is different between your code and mine is..

    1) I use a lowercase 'c' for the drive specification.
    2) I used escaped backshashes.

    Now I've used forward slashes before along with a drive specification, but I've always used a lowercase drive letter. I'd give that a shot.

    Hope this helps..
    Rich

Re: No useful device on path to madness
by schumi (Hermit) on Sep 29, 2001 at 22:22 UTC
    I tried this in several possible settings, with different locations of the script itself, different paths to the executable, including the one you specified, and they all worked fine for, both with and without the "C:" in the path to the executable.

    However, I tried it with a different executable, as I don't have the tkwarn.exe - I had it open my editpad. So all I can imagine is that the error message your getting is actually an error from tkwarn.exe and not from the script itself.

    Update: All this was on a W2k box, with ActiveState 5.6.1.

    --cs

    This may or may not help. Time is late. Don't hold it against me.