Question

I've created a Python script that works fine from command line, I use the print sentence to display few status messages. 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.

I'm using the following plist file:

<?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.

What I'm doing wrong?

Was it helpful?

Solution

I've been able to see the output in log.txt file just flushing buffers from python script. I've been adding sys.stdout.flush() where I needed to see the output immediately. What is not clear to me is why at launchd unload time, the buffers are lost and not written into log file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top