Solved

shell command through perl script

Posted on 2004-08-19
5
214 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
Comment Utility
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 166 total points
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

772 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

10 Experts available now in Live!

Get 1:1 Help Now