Perl相当于PHP的escapeshellarg

Zac*_*112 14 php perl

要转义要用作shell参数的字符串,我们使用函数escapeshellarg()in PHP.是否Perl具有同等功能?

dax*_*xim 31

String::ShellQuote,但大部分时间都不需要这样做.您可以通过仔细编程来避免调用shell.例如,system获取参数列表而不是字符串.

最佳实践:

use IPC::System::Simple qw(systemx);
systemx($command, @arguments);
Run Code Online (Sandbox Code Playgroud)
require IPC::System::Simple;
use autodie qw(:all);
system([@allowed_exit_values], $command, @arguments);
Run Code Online (Sandbox Code Playgroud)

  • 是的,如果可能的话,尽量避免使用外壳. (5认同)
  • 很好的回答[XY问题](http://www.perlmonks.org/index.pl?node_id=542341)与适当的解决方案.:) (3认同)