djdacore
Posts: 90
Joined: Tue Dec 09, 2014 7:47 pm

print output to something

Sun Jan 17, 2016 4:59 pm

If I have a python code that have a few print "test" in it.
Like print "button 1 is pressed...".

If I start that program it will give the output, but how can I get it to somewhere else. Are there more options for that?
If I want to see output of a started program I need to start the script again on another pc.

Thats why I ask this, because I would like to start the python code just once.

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

Re: print output to something

Sun Jan 17, 2016 5:20 pm

Hello,
there is syslog and logging, just to name two.

https://docs.python.org/2/library/syslog.html
https://docs.python.org/2/howto/logging.html

logging is very useful. It can log to console, to a file, and many more things.

Regards,
Gerhard

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: print output to something

Sun Jan 17, 2016 5:22 pm

Code: Select all

pi@raspberrypi ~ $ cat djdacore.py
print ("button 1 is pressed")

pi@raspberrypi ~ $ python djdacore.py > djacore.txt
pi@raspberrypi ~ $ cat djacore.txt
button 1 is pressed
pi@raspberrypi ~ $

djdacore
Posts: 90
Joined: Tue Dec 09, 2014 7:47 pm

Re: print output to something

Sun Jan 17, 2016 5:46 pm

OK a file is possible, nice, but how about a window where you can see live output coming in, is there somewhere a solution for that?
So the raspberry streams the output to another, for example a Windows pc, and have a window there where you can see the output?

Now I start the python by using Putty and start the python code again and again....

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: print output to something

Sun Jan 17, 2016 5:56 pm

djdacore wrote:OK a file is possible, nice, but how about a window where you can see live output coming in, is there somewhere a solution for that?
I've done this several times over the years. You can, of course, get fancier with it, but one simple solution is to open up two LXTerminal windows, and run the "tty" command in each to determine the tty for the window (it will be something like /dev/pts/1). Then, in the other window, run your Python program like:

$ /path/to/myprogram.py > /dev/pts/1

Now, you will get the stderr output in the main window (which will, by assumption, be small or non-existent), but the stdout output will be displayed in the other window.
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: print output to something

Sun Jan 17, 2016 6:02 pm

You can start the program in a "screen" session. Then you can disconnect/close the window and it will stay running. Then you can reconnect to the session from any terminal session (more than one at a time, if you wish) and see the same output.

Return to “Python”