drifterf
Posts: 134
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

View print data of all scripts running in one terminal ?

Thu Dec 20, 2018 7:31 pm

Hi, i have a few scripts running on startup for various things i am messing around with. everything works as needs be but i wondered how to have 1 terminal script running which will show me all the "print" data that is show throughout all the scripts i have running.

for example if i have script "1.py" running which presents the text "number 1" when it is programmed to, and another running along side called "2.py" which displays "number 2"

how can i have 1 script running which will show me the live "print" outputs of all of the scripts in 1 place ?

thanks, hope this makes sense.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: View print data of all scripts running in one terminal ?

Thu Dec 20, 2018 7:41 pm

It sounds like you are looking for screen(1).

It also sounds like this has nothing to do with Python per se, but is rather a general systems question.

How are you currently launching all of your scripts? What "run this stuff on startup" method are you using?
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

drifterf
Posts: 134
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Re: View print data of all scripts running in one terminal ?

Thu Dec 20, 2018 8:31 pm

im running 2 scripts on startup editing the rc.local .

one script to read a rfid and activate a gpio and another as a exit button which activates the same gpio.

i cant compile them together at moment due to random things on small project we are doing.

could i use this is monitor the state of both scripts ?

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: View print data of all scripts running in one terminal ?

Thu Dec 20, 2018 9:05 pm

Where is the output from the scripts currently going?

It is generally not a good idea to run things that generate output (output that continues on for the life of a process and which you need to be able to see and refer to) in rc.local, since it is somewhat undefined where the output of rc.local goes.

However, that all said, you could probably get with my usual rc.local hack, which is to put this line in your rc.local (make it the first active line - after all the comments and stuff - i.e., just before the "# Print the IP address" line):

Code: Select all

exec > /tmp/rc-local.out 2>&1;set -x
Now all of your output will end up in /tmp/rc-local.out, which you can monitor via, e.g.:

Code: Select all

$ tail -f /tmp/rc-local.out
Will that work for you?
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

ghp
Posts: 1399
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: View print data of all scripts running in one terminal ?

Thu Dec 20, 2018 9:19 pm

Background processes can log to systemd, which is the linux service writing the log files in /var/log.
There is a logging framework handler writing into this system. Check python logging framework https://docs.python.org/3/library/logging.html for the basics.
For the loggers into systemd, see https://stackoverflow.com/questions/345 ... via-python for some ideas.
You can follow the logs by using 'tail -f /var/log/<name_of_logfile>' in a console.

Return to “Python”