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

I have written a simply script that runs perfectly on Perl 5, but one line that fails on Perl 4. It is simply this...
qx(asp.exe > asp.txt);
I have also tried the back-ticks...
`asp.exe > asp.txt`;
Neither work in Perl 4 and in this case, I MUST use version 4 - no option. Is it the redirection of the output that is causing the problem? Is there another way to do this? Thank you! Glenn.

Replies are listed 'Best First'.
Re: Perl 4 qx doesn't work
by davorg (Chancellor) on Dec 18, 2001 at 18:58 UTC

    qx wasn't introduced until about 5.005, so it's no surprise that it doesn't work on Perl 4. Don't know about backticks. I've never used Perl 4 as it was replaced over seven years ago, long before I started using Perl.

    Perhaps you could try system instead.

    I'm interested in why you have to use Perl 4. As I said before, it is very out of date and was replaced with something far better over seven years ago. I believe there are still outstanding CERT security advisories against Perl 4, so using it is potentially very dangerous. Please upgrade to something more recent.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Thank you, I will look at system. I have to use Perl 4 perl.exe as part of a Tivoli installation. My only other option would be to use Per2Exe to convert it, but the company won't buy it for me. I will look into the system command. Thank you!

        Sounds like someone should be getting in touch with IBM to find out why they're using a very out of date version of Perl then.

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

(tye)Re: Perl 4 qx doesn't work
by tye (Sage) on Dec 18, 2001 at 20:13 UTC

    Backticks were supported in Perl 4. But the various Perl 4 ports to DOS-like systems had to use different tricks to get enough memory to be able to run Perl. So I suspect the problem is that asp.exe doesn't like being run from whatever extender your particular port of Perl 4 was built using.

    Perhaps you would have better luck with something like:

    system("start asp.exe > asp.txt") and die "'start asp.exe' failed ($?): $!\n"; # or system('start '.$ENV{COMSPEC}.' /c "asp.exe > asp.txt"') and die "'start cmd asp.exe' failed ($?): $!\n";
    Since you appear to be ignoring the results returned by qx//, you should be using system instead.

    Note that those are just guesses about how to "escape" the theorized problem with the "extender" and other combinations may be required (such as dropping "start" from the second example).

            - tye (but my friends call me "Tye")
      Thank you all for your help. I have decided to write the data to an array rather than a text file (which I should have been doing originally - but I'm still too new).
      @perfdata = `asp.exe` || die "Couldn't run asp.exe: $!\n";
      Thank you for all of your suggestions!!
Re: Perl 4 qx doesn't work
by Juerd (Abbot) on Dec 18, 2001 at 19:01 UTC
    If it's failing, there must be some sign of failure. Is there an error message? Is asp.exe even executed? What does and what doesn't happen?
    Or should we just guess what your problem is?

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      Sorry, no error at all - nothing. There is a pause that is the same length as when I run the command from the command prompt rather than the script, but no error message at all. Another person has suggested I look into the system function. I'll start there. Thank you for taking the time to comment.