将输出从exec发送到文件perl

123*_*123 5 bash perl

问题

在perl中运行exec时,我无法将输出重定向到文件.

我在exec中运行vlc但是因为我怀疑每个人都设置了我已经用下面的echo替换它,它显示了相同的行为示例.

我只对exec'命令'感兴趣,'args'格式的exec不是那个产生shell的格式,因为它生成了一个带有vlc的子shell,它仍会打印到屏幕+其他问题,干净地杀死它.


use strict;
use warnings;

my $pid = fork;
if (!defined $pid) {
    die "Cannot fork: $!";
}
elsif ($pid == 0) {
    exec "/usr/bin/echo","done";
}
Run Code Online (Sandbox Code Playgroud)

试着

exec "/usr/bin/echo","done",">/dev/null";
Run Code Online (Sandbox Code Playgroud)

正如预期的那样只打印">/dev/null",但值得一试.

exec "/usr/bin/echo done >/dev/null";
Run Code Online (Sandbox Code Playgroud)

运行sh然后运行echo,在这里工作,但不是我在vlc的实际问题,我想我会包括,因为有人肯定会建议它.

当使用'command','args'到文件时,如何重定向此exec的输出?

额外

如需更多信息,请询问.