The problem in a nutshell – I am writing a GUI wrapper for a command line utility (GPSBabel) and want to show the output of the command line on an error. I am a very inexperienced Python programmer.
Calling the program from the command line as follows
Code:
neill@NeillsPC:$ gpsbabel -igarmin -f/dev/ttyS1 -o zzz -F/home/neill/temp
produces the following output to the screen
[ERROR] GPS_Packet_Read: Timeout. No data received.
GARMIN:Can't init /dev/ttyS1
This is what I would like to show the user of the GUI but I can find no way of doing so.
I though that sending the output to the file would be a good start. From the command line I changed the command to
Code:
gpsbabel -igarmin -f/dev/ttyS1 -o zzz -F/home/neill/temp > /home/neill/temp/err.log 2>&1
which sent everything to the file err.log as expected.
In my program I call GPSBabel with
Code:
result = os.spawnlp(os.P_WAIT, 'gpsbabel', 'gpsbabel', dataString, inputFormatStr, inputFileStr, outputFormatStr, outputFileStr)
and can not see how to change that to be the same as my command line option.
I also tried
Code:
import sys
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
with stdout and stderr before calling the spawn.
Now I am stumped. Please help me some one even if only by telling me that it is impossible.
Thanks!
Neill
Bookmarks