0

I have a running python program (on Amazon linux server). This program was started by crontab.

How can I view its content stdout without stopping it?

2 Answers 2

3

You could just read the proc filesystem :

tail -f /proc/28897/fd/1

28897 is the process id.

You can get the process id using ps

For instance : ps aux | grep myScript.py

Sign up to request clarification or add additional context in comments.

5 Comments

Have you given the right process id ? Which command are you talking about ?
command "tail -f /proc/<my process id>/fd/1". I use "print" in my python program
this should definitively work that's weird, maybe try /fd/2
Are you sure your program is in a state where it should be outputting messages? tailing on a file descriptor won't give you any old messages, it will only print new ones. Consider either writing to a file via docs.python.org/2/library/…, or use shell redirection via ./foo.py >> bar.txt and then run tail -f bar.txt from a terminal
redirect to a file works for me. Thanks Oliver Baumann and Loic
2

Elaborating on Loïc's answer:

The "1" at the end of tail -f /proc/28897/fd/1 denotes the stream you want to look into. 0 is STDIN, 1 is STDOUT, 2 is STDERR (https://en.wikipedia.org/wiki/File_descriptor)

Adding this as it can be quite cryptic to understand the black magic behind FDs, and as I don't have enough rep to comment ;-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.