Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

running command from within perl script

by manishrathi (Beadle)
on Oct 11, 2010 at 19:27 UTC ( [id://864678]=perlquestion: print w/replies, xml ) Need Help??

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

I want to run a command line command from within a perl script. How can I run command line command from Perl script ?

I have certain workflow jobs in the system hannging in there for more than a month and are useless. These jobs need to removed from within system. I can do it manually deleting them one by one by using "iwrmjobs jobname" (This is interwoven specific command), which is time taking and laborious. Is there a way, I can script a program where I can include this command to run in a loop ? I dont know, how to run a command line command from within script.

I know hoe to run commands from batch file. I want to know how to run commands from a script.

Please let me know, how to run comand line commands from script with a small example, if possible.

Thanks

Replies are listed 'Best First'.
Re: running command from within perl script
by amir_e_a (Hermit) on Oct 11, 2010 at 19:47 UTC

    The simplest way is to use the "system" function.

    If you want to capture the output of the program, use backticks:

    my $program_output = `programname`;

    For a more advanced, but harder to use way to do the same thing, see IPC::Open3.

Re: running command from within perl script
by kcott (Archbishop) on Oct 11, 2010 at 19:44 UTC

    Is this the sort of thing you were after?

    ken@Miranda ~/tmp $ perl -wE 'while (<>) { system $_ }' pwd /home/ken/tmp date Tue, 12-Oct-2010 6:40:53 AM AUSEDT ken@Miranda ~/tmp

    -- Ken

Re: running command from within perl script
by Anonymous Monk on Oct 11, 2010 at 19:41 UTC
      Fwiw, along with those commands,I find the $? variable to be useful for checking return codes from a system or backtick system call. --Ray
Re: running command from within perl script
by morgon (Priest) on Oct 11, 2010 at 20:16 UTC
    Please let me know, how to run comand line commands from script
    Wrong question. You ask for a fish when you should ask to be taught fishing.

    Your question should have been:

    Please let me know, how to search for answers (to questions that have been asked dozens of times before).
    And the answer to that would be the "search" field at the top of the page - or are you just being lazy?
      Have to agree with morgon.

      Go buy Learning Perl and gather the patience to go through it thoroughly.

      When you're done, you'll be able to do all kinds of amazing things at will, including your request. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://864678]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found