Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: exec not working?

by rovf (Priest)
on Jan 30, 2012 at 11:19 UTC ( #950752=note: print w/replies, xml ) Need Help??

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

although perl is on the path environment variable
How did you verify this? Did you check the environment in exactly that shell in which you were executing the Perl program?

Did you also check whether ther are maybe TWO files with a name like perl.* in your PATH?

Ronald Fischer <>

Replies are listed 'Best First'.
Re^4: exec not working?
by UVB (Acolyte) on Jan 30, 2012 at 21:06 UTC
    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.

      ... or die sprintf "ERRRR(%d)(%s)(%d)(%s)", $!,$!,$^E,$^E; ... or die sprintf "ERRRR(%d)(%s)(%d)(%s)", $!,$!,$^E,$^E;

      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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2018-05-22 16:23 GMT
Find Nodes?
    Voting Booth?