Perl 呼叫外部程式命令差異

  • Exp1.

    system("/usr/local/share/ca-certificates/; sudo update-ca-certificates; sudo systemctl restart docker.service");

  • Exp2.

    system("sh", "script.sh", "--help" );

  • Exp3.

    system("sh script.sh --help");

  • Exp1.

    exec("vi abc.txt");

  • Exp1. $cmd_msg 內就是回傳執行的結果

     $cmd_msg = `ls -l`;

  • Exp2. 搭配 2>&1 可讓所有訊息都導回來

     $cmd_msg = `sudo apt update -y 2>&1`;

  • Exp3. 也可使用 qx/ / 語法

     $cmd_msg = qx/script.sh --option/;

  • tech/perl_exec.txt
  • 上一次變更: 2021/01/03 23:16
  • jonathan