Solved

shell command through perl script

Posted on 2004-08-19
5
215 Views
Last Modified: 2013-12-26
how do i execute a shell command through a perl script?
0
Comment
Question by:hawky86
5 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 168 total points
ID: 11846677
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 166 total points
ID: 11858060
You could also use qx`` or open or fork exec
0
 
LVL 44

Assisted Solution

by:Karl Heinz Kremer
Karl Heinz Kremer earned 166 total points
ID: 11921029
Do you just need to execute the command, or do you also need to either provide input to the shell command, or process the output of your shell command? If that's a requirement, you can use a pipe:

# to read from a program use something like this
open(MY_PIPE, "/bin/ls |");

while (<MY_PIPE>)
{
    # do something with the output read from the pipe
}
close(MY_PIPE);

# to write to a program use something like this:
open(MY_PIPE, "| sort");
print MY_PIPE "9999";
print MY_PIPE "8888";
print MY_PIPE "0000";
close(MY_PIPE);

# you need to provide your own error handling
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now