我可以用 system
在 Perl 5 中运行外部程序。我喜欢想system
就像 Perl 中的微型“Linux 命令行”。但是,我找不到 system
的文档。在 Perl 6 中。等价物是什么?
最佳答案
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
另见此 2014 Perl 6 Advent post on "running external programs" .
关于perl - 如何使用 Perl 6 运行外部程序? (例如 Perl 5 中的 "system"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29547490/