简体   繁体   English

如何在Perl中调用Unix“脚本”命令?

[英]How to invoke Unix “script” command in Perl?

I'm sure this is an easy fix, but I need to use "script" (and not collect standard in/out/error) for my project. 我确信这是一个简单的修复程序,但是我需要为我的项目使用“脚本”(而不是收集标准输入/输出/错误)。 I'm somewhat new to Perl, so please bear with me. 我对Perl有点陌生,所以请多多包涵。

I have a Perl script that works fine. 我有一个运行良好的Perl脚本。 When I run it I generally type script > filename before I run Perl. 运行它时,通常在运行Perl之前先输入script > filename

$script > file.log
bash-3.2$ perl foobar.pl

This runs fine, and when I'm done I type exit or control D to stop the script and save the file. 这样可以很好地运行,完成后,我输入exit或控件D停止脚本并保存文件。 All I'd like to do is incorporate the script command in Perl and then automatically capture the file when the program stops running (12-16 hours). 我要做的就是将script命令合并到Perl中,然后在程序停止运行(12-16小时)时自动捕获文件。 The problem I have is that is I call in system("script > file.log"); 我的问题是我在system("script > file.log"); and them call system("perl foobar.pl"); 然后他们调用system("perl foobar.pl"); it hangs at the bash-3.2$ prompt. 它挂在bash-3.2$提示符下。 The only way to get Perl to work is control D or exit, stopping the script function. 使Perl正常工作的唯一方法是控件D或退出,从而停止脚本功能。

Anyone have any idea how to fix this? 有人知道如何解决此问题吗? While it's easy to start with script before invoking Perl, if I'm a mole and forget, I have to rerun the program (which takes a long time). 虽然在调用Perl之前很容易从脚本开始,但是如果我讨厌并且忘记了,我必须重新运行该程序(这需要很长时间)。

您是否考虑过使用system("script -c 'perl foobar.pl' file.log")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM