klintkrossa
Posts: 81
Joined: Tue Nov 10, 2015 3:06 pm

How can I make a os.system go quiet

Mon Dec 12, 2016 6:43 pm

Hello,
I know this is a dup. I do not know what it may be called.
I have a program to set my clock, I would like to run it in the background when I tried "sudo python3 set_time.py &" the system(...) sent back a replay.

How do I make that go quiet or is there a way to set the system clock from python3 without os.system??

here is the code

Code: Select all

#!/usr/bin/python3

from time import sleep
import serial
from pynmea import nmea
from os import system
WT = True
ser = serial.Serial(port='/dev/ttyACM0',
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
    )
try:
    while WT:
        myline = ser.readline()
        myline= myline.decode("utf-8")
        if(myline.startswith('$GPRMC')):
            gprmc = nmea.GPRMC()
            # Ask the objest to parse the data
            gprmc.parse(myline)
            time = gprmc.timestamp
            date = gprmc.datestamp
            valid = gprmc.data_validity
            longitude = gprmc.lon
            latitude = gprmc.lat
            londir = gprmc.lon_dir
            latdir = gprmc.lat_dir
            gpstime = "20"+date[4:6]+date[2:4]+date[0:2]+" "+time[0:2]+":"+time[2:4]+":"+time[4:6]
            if valid == "A":
                system('sudo date -u --set="%s"' % gpstime)##############################################
                sleep(10)
        else:
            pass
except KeyboardInterrupt:
    exit()
the pound's marks the spot

thanks
a redirect will be great
Thanks
This is not like any other bulletin boards that I have been on. Been flamed on other BB's so bad I was afraid to ask.

All my Raspberry Pi's are like the Hessian artilleryman of Sleepy Hollow.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: How can I make a os.system go quiet

Mon Dec 12, 2016 7:22 pm

I think you could do

Code: Select all

system('sudo date -u --set="%s" > /dev/null 2>&1' % gpstime)
which should redirect the output of that script.

Alternatively, you could use the subprocess module and just assign the output to a variable.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

klintkrossa
Posts: 81
Joined: Tue Nov 10, 2015 3:06 pm

Re: How can I make a os.system go quiet

Mon Dec 12, 2016 11:15 pm

thanks it worked
Thanks
This is not like any other bulletin boards that I have been on. Been flamed on other BB's so bad I was afraid to ask.

All my Raspberry Pi's are like the Hessian artilleryman of Sleepy Hollow.

Return to “Python”