我想运行一些命令(例如command
)使用perl的system()
。认为command
从 shell 运行如下:
command --arg1=arg1 --arg2=arg2 -arg3 -arg4
我该如何使用system()
to run command
与这些论点?
最佳实践:避免 shell,使用自动错误处理 -IPC::System::Simple.
require IPC::System::Simple;
use autodie qw(:all);
system qw(command --arg1=arg1 --arg2=arg2 -arg3 -arg4);
use IPC::System::Simple qw(runx);
runx [0], qw(command --arg1=arg1 --arg2=arg2 -arg3 -arg4);
# ↑ list of allowed EXIT_VALs, see documentation
编辑:接下来是咆哮。
eugene y 的答案包括系统文档的链接。在那里我们可以看到一段每次都需要包含的代码system
适当地。尤金·伊的回答仅显示了其中的一部分。
每当我们遇到这种情况时,我们都会将重复的代码捆绑在一个模块中。我将其与正确的简单异常处理进行了比较Try::Tiny
, 然而IPC::System::Simple
as system
做得对没有看到社区如此迅速地采用。看来需要更频繁地重复。
So, use autodie
! Use IPC::System::Simple
!省去您的乏味,请放心您使用经过测试的代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)