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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Running a Command Line from your Program

Replies are listed 'Best First'.
Re: Running a Command Line from your Program
by IraTarball (Monk) on Oct 16, 2001 at 22:08 UTC
    try system or backticks. They block until the called program completes. Backtick (which are ` as opposed to ') return a string of what was sent to STDOUT by the program. Try $bin = `ls /usr/bin`; to test it out.

    BTW. $? holds any error if the called program fails.

    Ira,

    "So... What do all these little arrows mean?"
    ~unknown

Re: Running a Command Line from your Program
by broquaint (Abbot) on Oct 16, 2001 at 22:08 UTC
    To run a command line program use system()
    system("wzzip -yp temp.zip file.txt");
    To get the output of a command use `` (backticks)
    $output = `wzzip -yp temp.zip file.txt`;
    These are the two most common ways to run command line programs (and most other programs for that matter).
    HTH

    broquaint

Re: Running a Command Line from your Program
by hopes (Friar) on Oct 16, 2001 at 22:24 UTC
    This is nearly a FAQ
    Please read this

    You'll be interested in system,exec,qx or backticks (eg. `ls -l /home/hopes`)
    You migth also do a supersearch for examples
    Hope this helps
    Hopes
Re: Running a Command Line from your Program
by Ven'Tatsu (Deacon) on Oct 17, 2001 at 01:57 UTC
    The only method I have not seen mentioned yet is open with a pipe. There are more examples of using open (and others) in perlipc.
Re: Running a Command Line from your Program
by the_slycer (Chaplain) on Oct 16, 2001 at 22:12 UTC