lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Using os to execute a program

Mon May 19, 2014 8:26 pm

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.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Using os to execute a program

Mon May 19, 2014 8:39 pm

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).

Return to “General discussion”