Perl 中的系统和反引号和管道之间有什么区别?

问题描述:

Perl 支持三种(我知道的)运行外部程序的方式:

Perl supports three ways (that I know of) of running external programs:

系统:

   system PROGRAM LIST

如:

system "abc";

反引号:

`abc`;

通过管道运行:

open ABC, "abc|";

它们之间有什么区别?以下是我所知道的:

What are the differences between them? Here's what I know:

  1. 您可以使用反引号和竖线轻松获取命令的输出.
  2. 就是这样(在未来的编辑中更多?)

  • system():运行命令并返回命令的退出状态
  • 反引号:运行命令并返回命令的输出
  • pipes : 运行命令并允许你使用它们作为句柄
    • system(): runs command and returns command's exit status
    • backticks: runs command and returns the command's output
    • pipes : runs command and allows you to use them as an handle
    • 反引号也将执行程序的 STDOUT 重定向到一个变量,然后系统将其发送到主程序的 STDOUT.

      Also backticks redirects the executed program's STDOUT to a variable, and system sends it to your main program's STDOUT.