Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

[solved] how do I run an external command

by scsijon (Initiate)
on Feb 19, 2013 at 11:55 UTC ( #1019532=perlquestion: print w/replies, xml ) Need Help??
scsijon has asked for the wisdom of the Perl Monks concerning the following question:

I am VERY new to perl ( a few days only) although I can work through most programs across languages nowadays given time and decent referance url's.

I need to run something like this:

 $package_category = (./support/find_cat $package_name $package_description)

I can run the shell equivalent in a Terminal Console and have it OK, But I can't seem to work out how to do it from withing the perl program.

the format I am trying to match is:

$output_variable = relative_file_path/external_command_filename_to_run + $input_variable1 $input_variable2 $output_variable is what I get back; and $input_variable1 and 2 are what the perl script feeds in.

And it will run as part of a loop with different input_variable entries each time, hopefully giving the correct output variable back.

I have already had a look through the similar varying messages across some of your pages, but they don't seem to match what I am attempting and I am hoping someone can either help directly with just code or (better) both code and a breakdown on what is what so I can understand it as well as use it.

Thanks in advance and anticipation of an easy fix.

Replies are listed 'Best First'.
Re: how do I run an external command
by vinoth.ree (Monsignor) on Feb 19, 2013 at 12:16 UTC

    Go through this link to get to know how to Execute external command

    You can use the backtics to execute your external program and capture its stdout and stderr.

    By default the backticks discard the stderr and return only the stdout of the external program.


    qx() is a alternative to using back-quotes to execute external commands.

Re: how do I run an external command
by Anonymous Monk on Feb 19, 2013 at 13:02 UTC
Re: how do I run an external command
by parser (Novice) on Feb 19, 2013 at 16:37 UTC
    Secret tip: If you spell the language Perl I'll bet nobody will even notice you are VERY new ;-) Welcome to the Perl universe. Warning, it is very addictive!

      thank you all, ESPECIALLY ree, many smilies to you in thanks

      from reading the link to the perlhowto site and puzzleing for quite a while as to why it didn't work as it says it should 'the penny dropped'.

      I had origonally been using ' (on the key with ") amongst the character sets I had tested and not ` (on the key with ~).

      Final code in case anyone else comes across the need is,

      $package_category = `./support/find_cat $package_name $package_description` ;

      And a note to parser, down here in australia, Perl is taken to mean something like, she's a beaut shella or great campsite or tasty thirst quenching drink (usually beer), definately not a programming language! Sorry!

      a final thanks to all :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019532]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-06-28 04:28 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (623 votes). Check out past polls.