perl - 如何使用 Perl 6 运行外部程序? (例如 Perl 5 中的 "system")

标签 perl raku

我可以用 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/

相关文章:

string - 如何在 Perl 中的字符串中包含新行?

perl - 如何打开 OO 风格的管道?

windows - 将 Unicode 字符打印到 shell

mysql - 在 rakudo-star docker 镜像上安装带有 DBIish 的 mysql 的安装要求

exception - 我什么时候想要恢复 Perl 6 异常?

perl - 匿名哈希片-语法?

linux - git checkout --patch,但失败,无法在@INC 中找到 Git.pm

seq - 如何在 Perl 6 中将序列作为参数传递?

syntax - Perl6 : Adding a sigil with Slangs

perl - 获取 XML::XPath 中的节点集大小