There are other ways as well.

You can use the system() function which forks into a child process, waits 
for the process to complete, and returns..

system("/bin/ls");
@FILES = system("/bin/ls");

And you can use the exec() function.  This function does not fork a child 
process.  According to the book I have here, exec() executes the command 
but never returns.  The exec() function fails only when the command you are 
attempting to run does not exist.  There are other caveats with exec().  I 
would use system().  On the other hand, I personally discourage the use of 
system() or exec() when I code because if I use the native abilities of 
Perl my code is cleaner, quicker, and more fun to code.  But thats just me.

eg: You can move files using system():

system("/bin/mv $PATH/to/file $PATH/to/newfile");

or you can use the move function:

use File::Copy

$file    = "/path/to/file";
$newfile = "/path/to/newfile";

move($file,$newfile);

The only thing extra about these is the use syntax at the top.  The second 
one is faster because Perl can do it all by itself happy lil self.  It 
doesn't have to spawn a shell process to do the work for it.

At 03:18 PM 07.25.2001 +0530, KK wrote:
>Hello Rahul -
>
>Just prepend and append the command with the symbol - ` - mind u, this is
>the back apostrophe, the first button on the keyboard from the left nad side
>on the second row from top. For eg.
>--------------------------- starts here ------------------
>#!/usr/local/bin/perl
>
>`ls -l`;
>--------------------------- ends here ------------------
>
>Kind regards.
>
>KK
>[EMAIL PROTECTED]
>
>
>----- Original Message -----
>From: Rahul Garg <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Wednesday, July 25, 2001 2:14 PM
>Subject: Linux commands in perl
>
>
>hello Everybody ,
>
>
>Simple question......................
>
>How to run Linux commands in Perl code.......
>
>Waiting for Reply........
>Thanx in Advance...........
>Rahul
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]



- Jim

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861

-----BEGIN PERL GEEK CODE BLOCK-----      ------BEGIN GEEK CODE BLOCK------
Version: 0.01                             Version: 3.12
P++>*@$c?P6?R+++>++++@$M                  GIT/CM/J d++(--) s++:++ a-
 >++++$O!MA->++++E!> PU-->+++BD            C++++(+) UB++++$L++++$S++++$
$C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++   P++(+)>+++++ L+++(++++)>+++++$ !E*
+PP+++>++++n-CO?PO!o >++++G               W++(+++) N+ o !K w--- PS---(-)@ PE
 >*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+   Y+>+++ PGP t+(+++)>+++@ 5- X++ R@
 >*@$uS+>*@$uH+uo+w-@$m!                   tv+ b? DI-(+++) D+++(++) G(++++)
------END PERL GEEK CODE BLOCK------      ------END GEEK CODE BLOCK------


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to