Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Running unix commands within Perl Scripts

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-03-2010
Member
 
Join Date: Dec 2009
Posts: 204
Running unix commands within Perl Scripts
  

Hi ,

I am using the Linux operating system and as well as using perl scripting for specific task.I am new for perl programming but much familiar with linux.I want to execute the Linux commands in in the perl script.How it would be done.i will be highly obliged to you.

Thank you very much


Last edited by Ash maker : 09-03-2010 at 03:48 PM.
Reply With Quote
  #2  
Old 09-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Running unix commands within Perl Scripts

You can execute the Linux commands within the perl script file and can be more beneficial for you to execute the commands within the program.

This is one of the program which is embedded with the Linux commands and will execute successful.


Code:
{
    my $dir = './logs';
    opendir my $dh, $dir or die "Can't opendir '$dir': $!\n";
    my @files = grep { ! -d "$dir/$_" and ! /file1/ } readdir $dh;
    print "$_\n" for @files;
}
Reply With Quote
  #3  
Old 09-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
exec() and system() function within Perl Scripts

exec() and system() function:

There are two functions are available in Perl named exec() function and system() that are being used to execute a system shell command.

The difference between these two functions are - system() creates a fork process and waits to see if the command succeeds or fails - returning a value.
On other hand,exec() doesn't evaluate anything after execution , it only executes the command.

Using backtick operator,you can capture output of the system call and it can't be used directly to get the capture output.
Reply With Quote
  #4  
Old 09-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
exec and system function with Perl Scripts

The system and exec function can be used during creation of script in perl.You can use these functions as below-

A simple example can show you the functionality and implementation of the functions which would be as follows -

Code:
$result = system(PROGRAM);
exec(PROGRAM);
The system function will manipulate the variable assigned in the parameter and the result variable is defined to get the output from this function.
Reply With Quote
  #5  
Old 09-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
Command-Line Programs in perl

Command-Line Programs in perl :

You need not use another editor and all to execute the programs in perl.You can easily run the small bit Perl programs on the command line.

You need to use some option which makes able you to execute the script.The -e option allows you to define Perl code to be executed by the compiler. For example, You can execute the "Hello William..." on the command line argument and it would print without any option.I am using it as a simple program to understanding for you.

Code:
$ perl -e 'print "Hello William...\n"'
You can use another -e option to print the output of the program.
Reply With Quote
  #6  
Old 09-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
Information about Perl components

You can get easily and readable information about the programming components of the perl.There are some commands with appropriate options will facilitate you to access the function and documentation about the perl programming -

To know more about the perl system function,just type the commands suggested below -

perldoc -f system

You can use the same method to access different components of the perl documentation.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Running unix commands within Perl Scripts"
Thread Thread Starter Forum Replies Last Post
Unix commands in iPhone Valliy Portable Devices 6 08-03-2012 03:51 AM
Macbook Pro is freezing on ‘Running Package Scripts’ ChittiBabu Portable Devices 2 15-01-2012 08:59 PM
Running PHP Scripts with Cron klite Software Development 5 04-11-2009 08:26 AM
An error has occured running scripts on this page Swine Flu Technology & Internet 3 17-08-2009 02:21 PM
Scripts not running in crontab Frasier Operating Systems 6 22-10-2008 02:33 PM


All times are GMT +5.5. The time now is 04:51 PM.