DavidCherryWelch has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have a couple of PERL scripts that I use to do tasks at work. After a recent install of an unrelated package, PERL no longer works. Fortunately for me, I have another box that is still working so I have a workaround but I would like to get my XP box fixed.

I wrote a simple script to demostrate the problem. Here it is:

print("Hello\n"); $ret=`echo dog`; print ("step 1 \$ret is $ret\n"); $SAScmd='c:\\apps\\sas\\sas9~1.1\\sas.exe' print("step 2 \$SAScmd is $SAScmd\n"); # run a SAS job # surprisingly this works $ret=`$SAScmd c:\\perl_test\\test.sas -batch`; print("step 3 \$ret is $ret\n"); # copy a file $ret=`copy c:\\perl_test\\test.sas c:\\perl_test\\test_new.sas`; print("step 4 \$ret is $ret/n");

Here is the output from the box that works:

Hello step 1 $ret is dog step 2 $SAScmd is c:\apps\sas\sas9~1.1\sas.exe step 3 $ret is step 4 $ret is 1 file(s) copied.

Here is the output from the XP box:

Hello step 1 $ret is step 2 $SAScmd is c:\apps\sas\sas9~1.1\sas.exe step 3 $ret is step 4 $ret is

On both machines, the SAS program is executed. On the XP box, echo and copy don't work. Any ideas?

Thank you for your help.

David

Replies are listed 'Best First'.
Re: PERL stopped working for built-in DOS functions under XP
by BrowserUk (Patriarch) on Jul 23, 2009 at 21:14 UTC

    What output do you get from both machines if you run this one-liner from a command line?

    c:>perl -le"print $ENV{comspec}"

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      COMSPEC isn't used.

      >perl -le"print '[',`dir /b a`,']'" [a ] >set COMSPEC=notexist.exe >perl -le"print '[',`dir /b a`,']'" [a ]

      Update: On the other hand, a bad PATH would be a problem.

      >c:\progs\perl5100\bin\perl -le"print '[',`dir /b a`,']'" [a ] >set PATH= >c:\progs\perl5100\bin\perl -le"print '[',`dir /b a`,']'" []
Re: PERL stopped working for built-in DOS functions under XP
by ikegami (Patriarch) on Jul 23, 2009 at 22:09 UTC

    Is that really your code? I notice you print out "/n" but you didn't show it in your output.

    What do $! and $? contain after each command? Actually, I'd rather see the output of perl -le"system 'echo dog'; print qq{$!/$?}"

    Are you running from the script from a console prompt?

    What's the output of perl -v?

Re: PERL stopped working for built-in DOS functions under XP
by syphilis (Archbishop) on Jul 23, 2009 at 23:07 UTC
    Could be finding another 'echo' and 'copy' - executables of the same name, for instance. Insertion of a shell metacharacter can be sufficient to force use of the shell commands. Try, eg:
    $ret = `echo dog <NUL`; $ret=`copy c:\\perl_test\\test.sas c:\\perl_test\\test_new.sas <NUL`;
    and see if that reinstates expected behaviour.

    Cheers,
    Rob