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()thanks
a redirect will be great