我可以system
在 Perl 5 中使用来运行外部程序。我喜欢把system
Perl 想象成一个微型的“Linux 命令行”。但是,我在 Perl 6 中找不到文档system
。什么是等效的?
问问题
562 次
2 回答
9
Perl6 实际上有两个system
从 Perl 5 替换的命令。
在 Perl6 中,shell
将其参数传递给 shell,类似于 Perl 5 system
,当它有一个包含元字符的参数时。
在 Perl6 中,run
尽量避免使用 shell。它将其第一个参数作为命令,其余参数作为该命令的参数,类似于 Perl 5 的system
当它有多个参数时。
例如:
shell('ls > file.log.txt'); # Capture output from ls (shell does all the parsing, etc)
run('ls','-l','-r','-t'); # Run ls with -l, -r, and -t flags
run('ls','-lrt'); # Ditto
于 2015-04-09T19:40:36.253 回答
5
除了使用shell
or run
(从 Perl 5 替换)之外system
,您还可以使用NativeCall
来调用 libcsystem
函数。
在我的 Windows 机器上,它看起来像这样:
use NativeCall;
sub system(Str --> int32) is native("msvcr110.dll") { * };
system("echo 42");
于 2015-04-10T17:54:40.773 回答