Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^4: exec not working?

by UVB (Acolyte)
on Jan 30, 2012 at 21:06 UTC ( #950839=note: print w/replies, xml ) Need Help??

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

This script:
# Test perl execution system "perl", "d:\\src_test\\perl\\"; system "echo %path%"; system "which perl"; exec "perl", "d:\\src_test\\perl\\";
Shows the path. The which program shows only the expected Perl.exe file. Here is the script output:
Hello world C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sys +tem32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies +\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\ +Program Files\WIDCOMM\Bluetooth Software\syswow64;D:\app\sql\product\ +11.2.0\client_1\bin;C:\Program Files (x86)\Java\jdk1.6.0_20\bin;d:\op +t\ant\bin;C:\Program Files\Scite;C:\Program Files (x86)\GnuWin32\bin; +C:\Program Files (x86)\WinMerge;D:\opt\apache-maven-2.2.1\bin;d:\orac +le;D:\opt\OracleXeClient\bin;D:\opt\OracleXe\app\oracle\product\10.2. +0\server\bin;D:\opt\SpringSource\spring-roo-1.2.0.RELEASE\bin;C:\Prog +ram Files\SlikSvn\bin\;C:\Program Files (x86)\Microsoft SQL Server\10 +0\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C +:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files ( +x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Prog +ram Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files ( +x86)\QuickTime\QTSystem\;C:\Program Files\7-Zip;C:\Program Files (x86 +)\Programmer's Notepad\;D:\Ruby187\bin;C:\Program Files (x86)\Microso +ft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\; C:\Program Files + (x86)\ActiveState Komodo Edit 6\;D:\opt\scala-\bin;c:\Program + Files\Sublime Text 2;C:\Program Files\TortoiseSVN\bin;C:\Program Fil +es (x86)\Windows Live\Shared;C:\Program Files\Common Files\Microsoft +Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Sha +red\Windows Live;d:\opt\strawberry\perl\bin;d:\opt\strawberry\perl\si +te\bin;d:\opt\strawberry\c\bin;d:\opt\util;D:\opt\SpringSource\spring +-roo-1.2.0.RELEASE\bin d:\opt\strawberry\perl\bin\perl.EXE Can't exec "perl": Invalid argument at D:\src_test\perl\ l +ine 5.
Note that the first system and the last exec statement are provided with identical arguments - the exec throws an exception but the same earlier call to system doesn't. I do have a separate, older Perl installation - not on the path - which was not completely removed. When I installed the new Perl, I didn't un-install that Perl except I did remove it from the path. If I now change the path back to point at the older Perl build, I get the same broken behaviour of exec.

So the problem is my installation. If I want to fix it I may have to fully un-install both Perls.

Thank you for your help rovf.

Replies are listed 'Best First'.
Re^5: exec not working?
by Anonymous Monk on Feb 01, 2012 at 10:30 UTC
    ... or die sprintf "ERRRR(%d)(%s)(%d)(%s)", $!,$!,$^E,$^E; ... or die sprintf "ERRRR(%d)(%s)(%d)(%s)", $!,$!,$^E,$^E;
Re^5: exec not working?
by rovf (Priest) on Feb 01, 2012 at 09:47 UTC

    I think the bug is in your code: exec does not honour the PATH variable (see exec - PATH isn't mentioned anywhere).
    If you really want to use exec, give the full path (and the extension) of the perl.exe you want to use.

    Ronald Fischer <>

      Nope, exec doesn't care about path, the OS cares about path

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950839]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2018-01-20 00:25 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.