in reply to Re^6: exec not working?
in thread exec not working?

I don't know enough about Windoze, but doesn't it depend on which Windows API function is invoked, whether or not PATH is searched? Of course CMD.EXE always searches the PATH, but here, the process is started without intervention, but with exec, I don't see why this should be the case.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^8: exec not working?
by Anonymous Monk on Feb 01, 2012 at 11:31 UTC

    ... 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