in reply to Re: System call doesn't recognise '>'
in thread System call doesn't recognise '>'

Comspec contained the path to cmd.exe

But the snippet of code you included didn't work.

cmd.exe was indeed not part of the PATH.

I tried:

use Env qw(@PATH); #print "@PATH\n"; unshift @PATH, "C:\\windows\\system32\\cmd.exe"; #print @PATH; system "C:\\windows\\system32\\cmd.exe /C @array > $outfile"; shift @PATH;

The path to the command shell was added, but the result was still:

Can't spawn "cmd.exe": No such file or directory at D:\advanced_programming\test_syscall.pl line 26.

Or isn't it that what you suggested?

Replies are listed 'Best First'.
Re^3: System call doesn't recognise '>'
by Corion (Patriarch) on Dec 10, 2008 at 22:24 UTC
    unshift @PATH, "C:\\windows\\system32\\cmd.exe";

    That's not how the PATH environment variable works, neither in Windows nor in Unix. The PATH environment variable contains directories not executable files. Try

    unshift @PATH, "C:\\windows\\system32";

    instead, and consider not running a weirdly configured environment. Many Windows programs will fail if %WINDIR%\system32 is not in the path.

      use Env qw(@PATH); print "@PATH\n"; unshift @PATH, "C:\\windows\\system32"; print @PATH; system "C:\\windows\\system32\\cmd.exe /C @array > $outfile"; shift @PATH;

      It works!!

      Thank you very very much!

        If you had actually read and followed the writeups, you would know by know that the C:\\windows\\system32\\cmd.exe /C part is superfluous.

Re^3: System call doesn't recognise '>'
by almut (Canon) on Dec 10, 2008 at 22:57 UTC

    Something else to try:  Perl (Windows only) provides for this rarely used facility to set a custom command shell via the environment variable PERL5SHELL. In other words, on the command line that you're going to call your Perl program from, set that variable (prior to calling the program):

    set PERL5SHELL=c:\\windows\\system32\\cmd.exe /c

    (yes, with doubled backslashes)

    And maybe try something trivial first, e.g.

    #!perl system "echo foo >dummy";

    In theory, you should then find a file "dummy" with the content "foo".  In case that works, try your real command...