Re: How can I execute linux commands on terminal and catch the results?
- From: Jim Gibson <jimsgibson@xxxxxxxxx>
- Date: Tue, 30 Sep 2008 10:09:02 -0700
In article
<b3f4c9c1-621c-44c5-b95f-711c8d0034cb@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Daniel Nascimento <filhodan@xxxxxxxxx> wrote:
Hello everyone!
I'm learning perl and I need some help.
I want to write a script that execute commands into a linux terminal
and catch the results but I don't know how to do this.
There are several ways for a Perl program to execute external
processes, either system-provided utilities or programs written by you
or anybody else:
1. Use system function
2. Use backticks or qx operator
3. Use open with pipe mode
You can find out about these by consulting the built-in Perl document
utility perldoc:
perldoc -f system
perldoc perlop (search for qx)
perldoc -f open
There is additional information available with
perldoc perlopentut
For complex interaction with an external process, you can use the
IPC::Open2, IPC::Open3, or Expect modules.
Example: I want a script try to create a new user, but it has to
verify if the user is created before do it. If the user was already
created the script has to print a message for user informing something
like this "user already created"
On a linux system, you can read the /etc/passwd file to see if a user
exists. You can also make use of the getpw* family of functions to get
user information. See perldoc perlfunc and search for 'user and group
info' or, for example. 'perldoc -f getpwent'.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
.
- References:
- How can I execute linux commands on terminal and catch the results?
- From: Daniel Nascimento
- How can I execute linux commands on terminal and catch the results?
- Prev by Date: Re:regex and newline
- Next by Date: Re: regex and newline
- Previous by thread: Re: How can I execute linux commands on terminal and catch the results?
- Next by thread: if condition question
- Index(es):
Relevant Pages
|