Page 1 of 1

Using os to execute a program

Posted: Mon May 19, 2014 8:26 pm
by lilzz

Code: Select all

# Fetch Temperature Reading 
x = os.system("/opt/vc/bin/vcgencmd measure_temp >/xyz/pi_cpu_temp.txt") 
why need to use os.system to execute the executable?

why not just use
chmod 777+ vcgencmd
./vdgencmd measure_temp

That's the more common way i seen.

Re: Using os to execute a program

Posted: Mon May 19, 2014 8:39 pm
by sprinkmeier
lilzz wrote: why need to use os.system to execute the executable?

os.system allows you to call a program from a python script.
lilzz wrote: chmod 777+ vcgencmd
the file should alreasy be marked as executable so chmod should not be necessary.
mode '777' makes the file world-writable which is a bad idea. '755' is the usual mode for a program (everyone can read and execute, owner can also write).