简体   繁体   English

脚本在启动时不会产生输出

[英]Script does not produce output with launched

I've created a Python script that works fine from command line, I use the print sentence to display few status messages. 我创建了一个Python脚本,该脚本可以从命令行正常运行,我使用打印语句显示一些状态消息。 When I try to run the script using launchd, all print output does not appear, but the script works fine because for example it updates an sqlite database without problems. 当我尝试使用launchd运行脚本时,不会出现所有打印输出,但是脚本可以正常运行,因为例如它可以更新sqlite数据库,而不会出现问题。

I'm using the following plist file: 我正在使用以下plist文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.joanba.maslestorres.cat</string>
    <key>ProgramArguments</key>
    <array>
            <string>python</string>
            <string>/maslestorres.cat/jardiNet_datalogger.py</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/maslestorres.cat/</string>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/maslestorres.cat/log/out.txt</string>
    <key>StandardErrorPath</key>
    <string>/maslestorres.cat/log/err.txt</string>
</dict>
</plist>

It's supposed that print uses stdout so I expect that normal output goes to file /maslestorres.cat/log/out.txt . 假定print使用stdout,所以我希望正常输出到文件/maslestorres.cat/log/out.txt

What I'm doing wrong? 我做错了什么?

I've been able to see the output in log.txt file just flushing buffers from python script. 我已经能够看到log.txt文件中的输出只是从python脚本中清除缓冲区。 I've been adding sys.stdout.flush() where I needed to see the output immediately. 我一直在添加sys.stdout.flush(),我需要立即查看输出。 What is not clear to me is why at launchd unload time, the buffers are lost and not written into log file. 我不清楚的是,为什么在启动卸载时缓冲区丢失并且没有写入日志文件。

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

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