简体   繁体   English

如何从crontab执行的perl脚本中执行的可执行文件(cap)捕获STDOUT

[英]How to capture STDOUT from executable (cap) executed within a perl script executed from a crontab

Whew that is a long-winded title. 哇,这是一个漫长的标题。 But it explains my issue: 但这解释了我的问题:

I have a crontab that runs a perl script. 我有一个运行perl脚本的crontab。

That perl script runs a cap task, which outputs to STDOUT some status messages. 该perl脚本运行一个cap任务,该任务将一些状态消息输出到STDOUT。

The perl script is supposed to capture the STDOUT (currently using backticks) from cap and parse it. Perl脚本应该从cap捕获STDOUT(当前使用反引号)并进行解析。

Now, this works 100% fine when I run the script from a bash user. 现在,当我从bash用户运行脚本时,这可以100%正常工作。 However, when I run the script from a crontab, the perl script doesn't capture any output from the cap task. 但是,当我从crontab运行脚本时,perl脚本不会捕获cap任务的任何输出。

Has anyone dealt with anything like this before? 以前有没有人处理过类似的事情? Thanks. 谢谢。

Maybe your cap executables are died without emitting any message to stdout. 也许您的cap可执行文件已死,而没有向stdout发出任何消息。 Did you checking the success state of execution? 您是否检查了执行的成功状态?

Could you tried this? 你能试一下吗?

$check_result = `$cmd 2>&1`;
if ($?){
  die "$cmd failed with $check_result, $!";    
}

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

相关问题 Perl脚本来捕获反引号中执行的命令的stderr和stdout - Perl script to capture stderr and stdout of command executed in back-quotes 如何将从另一个perl脚本执行的Perl脚本的输出重定向到文件? - How do I redirect the output of Perl script executed from within another perl script to a file? 如何获取在Perl脚本中执行的程序的PID - How to get the PID of a program executed within a Perl script 在crontab中执行时,Perl脚本无法写入数据库,即使在手动执行时也可以写入 - Perl script unable to write to database when executed in crontab despite being able to write if executed manually 如何从其他Perl脚本获取在新cmd窗口中执行的脚本的输出? - How to get output of a script executed in a new cmd window from other perl script? 将环境变量设置为 shell 从 perl 脚本执行 - Setting environment variable to shell executed from perl script Perl脚本从crontab失败 - Perl script failing from crontab 如何从Perl脚本中捕获系统命令的stdin和stdout? - How can I capture the stdin and stdout of system command from a Perl script? 从Perl脚本中重新将输出重定向到stdout - Re-redirecting output to stdout from within Perl script 如何在“exec”执行的perl脚本上使用调试器 - How to use debugger on perl script executed by “exec”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM