|
| ||||||||||
| Tags: linux, perl programming, perl script, programming, script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Running unix commands within Perl Scripts
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 02:48 PM. |
|
#2
| ||||
| ||||
| 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;
} |
|
#3
| |||
| |||
| 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. |
|
#4
| ||||
| ||||
| 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); |
|
#5
| ||||
| ||||
| 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"' |
|
#6
| ||||
| ||||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 02:51 AM |
| Macbook Pro is freezing on ‘Running Package Scripts’ | ChittiBabu | Portable Devices | 2 | 15-01-2012 07:59 PM |
| Running PHP Scripts with Cron | klite | Software Development | 5 | 04-11-2009 07:26 AM |
| An error has occured running scripts on this page | Swine Flu | Technology & Internet | 3 | 17-08-2009 01:21 PM |
| Scripts not running in crontab | Frasier | Operating Systems | 6 | 22-10-2008 01:33 PM |