Perl equivalent of PHP's escapeshellarg

前端 未结 4 1837
我寻月下人不归
我寻月下人不归 2020-12-06 16:38

To escape the string to be used as shell argument we use the function escapeshellarg() in PHP. Does Perl have an equivalent function ?

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 17:32

    String::ShellQuote, but most of the time this is not needed. You simply can avoid invoking the shell by careful programming. For example, system takes a list of arguments instead of a string.

    Best practice:

    use IPC::System::Simple qw(systemx);
    systemx($command, @arguments);
    

    require IPC::System::Simple;
    use autodie qw(:all);
    system([@allowed_exit_values], $command, @arguments);
    

提交回复
热议问题