perl - 通过 perl 脚本调用 make 实用程序/文件

标签 perl makefile

有什么方法可以通过 perl 脚本调用 make 实用程序。 我在 myscript 中使用了以下代码

$cmd=system("/...path../make");
print "$cmd";

但它不起作用

最佳答案

您可以调用任何您想要的命令。为了简单起见,它通常在反引号中完成:

my $output = `make`;
print( $output );

另一种常用的技术是像读取文件一样打开一个进程:

my $filehandle;
if ( ! open( $filehandle, "make |" ) ) {
    die( "Failed to start process: $!" );
}
while ( defined( my $line = <$filehandle> ) ) {
    print( $line );
}
close( $line );

这样做的好处是您可以看到从流程交付的输出。

您可能希望通过将 2>&1 添加到命令行来捕获 STDERR 输出以及 STDOUT 输出:

my $filehandle;
if ( ! open( $filehandle, "make 2>&1 |" ) ) {
    die( "Failed to start process: $!" );
}
while ( defined( my $line = <$filehandle> ) ) {
    print( $line );
}
close( $line );

关于perl - 通过 perl 脚本调用 make 实用程序/文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17448672/

相关文章:

perl - 将 Perl 中的匿名 sub 写入文件以供以后使用

mysql - 根据数据库中的值重命名文件

mysql - 如何将数组的一部分插入MySQL?

perl - 是否有用于 AES 的纯 Perl 模块?

c - 我的 makefile 出错,标志没有得到适当处理。可能是什么原因?

linux - 向 cmake 添加库

c++ - 如何使用交叉链接器而不是 native 链接器

c++ - 有哪些 Makefile 生成工具?

c++ - 代码库未找到标准 C++ 库 header

file - Perl - 在制表符分隔的文本文件中拆分列并用新值替换列的问题