Re: How can I execute linux commands on terminal and catch the results?



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
.



Relevant Pages

  • Re: Translate VBScript Which gets Computer Names to Perl
    ... If the script works in VBScript, why are you trying to translate it? ... Perl, I would use VBscript. ... perldoc -f push ...
    (microsoft.public.scripting.vbscript)
  • Re: Perl equivalent to unix script
    ... handy with unix and unix scripting, however, I'm terrible at perl. ... What I'm looking to do with a perl script is the equivalent of the ... perldoc -f open ...
    (comp.lang.perl.misc)
  • Re: Help.. perl script to look for and then copy over any new files in a directory!
    ... > I am trying to write a perl script that will open a directory, ... > copy all new files to a temp directory. ... perldoc -f opendir ... I am using Perl 5. ...
    (perl.beginners)
  • Re: Noob wants Q&D pointer, regexp replacement.
    ... I do perl once every 5 years. ... perldoc -f readline ... This script takes at least two file names on the command line. ... first file is read and its contents stored in $contents. ...
    (comp.lang.perl.misc)
  • Re: Net::DNS
    ... function because you still use $rr within the foreach, ... > So I can find the all these object methods in the perl docs listed below? ... > the return value of 'grep'. ... > perldoc perlboot ...
    (perl.beginners)