How to execute shell command in a perl script?

https://stackoverflow.com/questions/3200801/how-can-i-call-a-shell-command-in-my-perl-script/21153038

1. 用`` 不显示执行结果 

  • my $files = `ls -la` — captures the output of the command in $files

2. 用system or exec 不显示执行结果 

  • system "touch ~/foo" — if you don't want to capture the command's output
  • exec "vim ~/foo" — if you don't want to return to the script after executing the command

3.用open 适合命令里有管道符时

  • open(my $file, '|-', "grep foo"); print $file "foo\nbar" — if you want to pipe input into
posted on 2021-11-23 15:37  guolongnv  阅读(61)  评论(0)    收藏  举报