... why ...

Hmm, found a bug, exec appears to cache path, so it works even if you undef $ENV{PATH}, where as system fails -- I still can't replicate the OPs condition :)

# path is undef from perl, system fails
$ perl -V:yo -Te " undef $ENV{PATH}; system q/perl -e die /" yo='UNKNOWN';
# path is undef from perl, exec succeeds
$ perl -V:yo -Te " undef $ENV{PATH}; exec q/perl -e die /" yo='UNKNOWN'; $ Died at -e line 1.
# path is undef from cmd.exe, exec fails
$ set path= $ C:\perl\5.12.2\bin\MSWin32-x86-multi-thread\perl.exe -V:yo -Te " und +ef $ENV{PATH}; exec qw/perl -e die /" yo='UNKNOWN';

# using the shell works, perl dies

$ perl -le " exec q{C:\WINDOWS\system32\cmd.exe /x /c }.qq{\x22perl - +e die\x22}; " $ Died at -e line 1.
# works , absolute path, cmd successfully launched, fails to find perl
$ perl -le " undef $ENV{PATH}; exec q{C:\WINDOWS\system32\cmd.exe /x / +c }.qq{\x22perl -e die\x22}; " $ 'perl' is not recognized as an internal or external command, operable program or batch file.
# shouldn't work, cmd.exe is still found but it shouldn't be found with a relative path and undef PATH
$ perl -V:yo -le " undef $ENV{PATH}; exec q{cmd.exe /x /c }.qq{\x22per +l -e die\x22}; " yo='UNKNOWN'; $ 'perl' is not recognized as an internal or external command, operable program or batch file.
# works, cmd.exe is not found
$ set path= $ C:\perl\5.12.2\bin\MSWin32-x86-multi-thread\perl.exe -V:yo -le " un +def $ENV{PATH}; exec q{cmd.exe /x /c }.qq{\x22perl -e die\x22}; " yo='UNKNOWN';

http://perl5.git.perl.org/perl.git?a=search&h=HEAD&st=grep&s=_exec

Perl_do_exec http://perl5.git.perl.org/perl.git/blob?f=win32/win32.c#l762
win32_execvp http://perl5.git.perl.org/perl.git/blob?f=win32/win32.c#l3644
win32_spawnvp http://perl5.git.perl.org/perl.git/blob?f=win32/win32.c#l3471

In reply to Re^8: exec not working? by Anonymous Monk
in thread exec not working? by UVB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.