One, System
Perl can also invoke the Shell's command with system, which, like Awk's system, returns a value that is also the exit state of the command it invokes.
Copy Code code as follows:
[Root@ax3sp2 ~]# Cat aa.pl
#! /usr/bin/perl-w
$file = "wt.pl";
System ("Ls-l wt.pl");
$result = System "Ls-l $file";
print "$result \ n"; #输出命令的退出状态
System "Date";
[Root@ax3sp2 ~]# Perl aa.pl
-rwxr-xr-x 1 root root 126 12-16 15:12 wt.pl
-rwxr-xr-x 1 root root 126 12-16 15:12 wt.pl
0
Thursday, December 16, 2010 15:58:34 CST
second, inverted quotation marks
The system function of Perl, like awk, cannot return the output of a command.
To get the output of a command, you have to use the same command as the shell itself: '
Copy Code code as follows:
[Root@ax3sp2 ~]# Cat bb.pl
#! /usr/bin/perl
print ' Date ';
Print "This is test \ n";
[Root@ax3sp2 ~]# Perl bb.pl
Thursday, December 16, 2010 15:51:59 CST
This is test
Third, exec
Finally, Perl can use Exec to invoke the shell's commands. exec is about the same as system, except that after calling exec, Perl quits immediately without continuing to execute the rest of the code.
Copy Code code as follows:
[Root@ax3sp2 ~]# Cat cc.pl
#! /usr/bin/perl
EXEC ("Echo is Test");
Print "Good Bye!\n"; #这句话不会被输出
[Root@ax3sp2 ~]# Perl cc.pl
This is test