def osCommand(commandStr): # by: D@CC # date: 2020 # used by: PiR2 # aka commandOS() # @purpose: to issue a system command and return the result # @param1: str commandStr eg: "vcgencmd measure_temp" # @returns: str commandResultStr eg: "temp=36.9'C" from subprocess import call #import os from os import system, name, remove from time import sleep #print("osCommand received commandStr:"+commandStr) commandResultStr="none" global g_fileArray #commandRFileName=g_fileArray[2] commandRFileName="/home/pi/Desktop/PiR2/files/commandResult.txt" # name is not a function, but a special variable if name == 'nt': _ =system('cls') else: if (commandStr=="clear"): print("before clear") _= system("clear") print("after clear") else: if (False): # in case no file exists, appending something will create it # for sure fh=open(commandRFileName, "a") fh.write("any") fh.close() # now remove it remove(commandRFileName) #endif # save result in txt file saveOutputStr=" >"+commandRFileName revisedCommandStr=commandStr+saveOutputStr #print("revisedCommandStr:"+revisedCommandStr) #invoke system command _= system(revisedCommandStr) fh=open(commandRFileName, "r") # read the result of the command commandResultStr=fh.readline() fh.close() #end if return commandResultStr #end if #end def osCommand()