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

This is another newbie question I'm afraid.
open(AT_LIST, ">>$at_file") ; # $at_file defined elsewhere foreach $bch (@branch_array) { AT_LIST = qx'AT, $bch' ; #One of many variations i've tried } close(AT_LIST);

As you can see from the above code I'm trying to run the windows command "AT" against several servers from within perl and write the output via filehandle to a text file. I've tried SYSTEM in many variations and can only collect the return code. After rereading (bits of) programming perl I realised I needed qx() but after trying many variations in the syntax can't for the life of me get it to run.

Is there a problem with using a filehandle ? is it plain impossible to do what I want ?
Or, as seems very likely, am I missing something very obvious here ?

Could some enlightened being point me in the right direction ?
Many thanks Alan

Replies are listed 'Best First'.
Re: Capturing output with qx()
by davorg (Chancellor) on Oct 08, 2001 at 19:24 UTC

    You print stuff to a file handle. I think you want something like this:

    print AT_LIST qx'AT $bch';

    I don't know much about the AT command, so I'm assuming it's similar to the Unix at command.

    I've removed the comma between AT and $bch as it looks to me like that's completely unnecessary - I could be wrong there. Also, don't you need to give AT at time?

    Note, also, that this will return the output from the AT call - not the output of the command that AT runs.

Re: Capturing output with qx()
by Fletch (Bishop) on Oct 08, 2001 at 19:37 UTC

    Also, if you use ' as your qx// delimiter then it won't do interpolation. See perldoc perlop for details.

Re: Capturing output with qx()
by data64 (Chaplain) on Oct 13, 2001 at 18:19 UTC

    I am not sure I understand why you need qx().

    If I understand your problem correctly, what you need is the backtick operator.

    so what you need is:

    $result = `AT $bch`; print OUTPUT $result;
      It's exactly what I was looking for. I was confused by system, qx, backticks et al :) Anyway, thanks to the three of you for your help I got something from each answer ! BTW I also managed to achieve what I wanted with system - albeit with more code. Thanks again Alan