SoFunction
Updated on 2025-04-08

Perl gets the execution result of the shell command

There are many ways:
1. Redirect the standard output or standard error output of the shell to a temporary file, and then read the execution result from the temporary file.
The advantage of this method is that it can save the standard output and the standard error output separately!

2. my $res = `ls`;
This method is very direct and I also want to shell

3. open( my $fh, "ls |") or die "$!";
while ( <$fh> ) {
print;
}
Using pipes is relatively novel.