为什么在反引号中出现语法错误,即使它在终端中有效?

Why do I get a syntax error in backticks, even though it works in terminal?

我正在尝试 运行 使用反引号在 Perl 中执行 Linux 命令。当我直接在 Linux 中 运行 时它工作,但是当 Perl 通过反引号完成它时,我得到这个错误:

sh: -c: line 0: syntax error near unexpected token `>'
sh: -c: line 0: `(/src/storageUtil --diagnostic 2> >(tee >(cat >&2) >&1)) > log.txt'

有问题的代码行是:

$output = `(/src/storageUtil --diagnostic 2> >(tee >(cat >&2) >&1)) > log.txt`;

任何有关可能导致此错误的原因的见解都将不胜感激。

谢谢

您可能使用 bash 在命令行上测试了您的代码,但是当您从 Perl 调用它时,您试图通过 sh 运行 它。

要么更改您的命令以与 Bourne shell 兼容,要么显式调用 bash