本文整理汇总了Python中subprocess.Popen.read方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.read方法的具体用法?Python Popen.read怎么用?Python Popen.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkEnclosureTemp
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def checkEnclosureTemp(self):
if self._settings.get(["dhtModel"]) == 1820 or self._settings.get(["dhtModel"]) == '1820':
stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"])), shell=True, stdout=PIPE).stdout
else:
stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout
sTemp = stdout.read()
sTemp.replace(" ", "")
if sTemp.find("Failed") != -1:
self._logger.info("Failed to read Temperature")
else:
#self._logger.info(sTemp)
self.enclosureCurrentTemperature = self.toFloat(sTemp)
#self._logger.info("enclosureCurrentTemperature is: %s",self.enclosureCurrentTemperature)
if self._settings.get(["dhtModel"]) != '1820':
stdout = Popen("sudo "+self._settings.get(["getHumiScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout
sHum = stdout.read()
sHum.replace(" ", "")
if sHum.find("Failed") != -1:
self._logger.info("Failed to read Humidity")
else:
self._logger.info(sHum)
self.enclosureCurrentHumidity = self.toFloat(sHum)
self._plugin_manager.send_plugin_message(self._identifier, dict(enclosuretemp=self.enclosureCurrentTemperature,enclosureHumidity=self.enclosureCurrentHumidity))
self.heaterHandler()
示例2: dataLogging
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def dataLogging():
#Open Log File
f=open('tempdata.txt','a')
now = datetime.datetime.now()
timestamp = now.strftime("%Y/%m/%d,%H:%M:%S")
cowName = cow()
config = ConfigParser.ConfigParser()
config.read("/home/pi/config.ini")
pipe1 = Popen('sudo ./2readADC', shell=True, stdout=PIPE).stdout
weight = pipe1.read()
# .communicate()
# exit_code = weight.wait()
cmd = ['sudo sh /home/pi/showTemp.sh']
pipe2 = Popen(cmd, shell=True, stdout=PIPE).stdout
temperature = pipe2.read()
outstring = str(timestamp)+","+weight+ ","+temperature+"\n"
f.write(outstring)
f.close()
print outstring
Popen('sudo bw_tool -I -D /dev/i2c-1 -a 94 -w 10:0', shell=True)
Popen('sudo bw_tool -I -D /dev/i2c-1 -a 94 -r 17 -v 0', shell=True)
Popen('sudo bw_tool -I -D /dev/i2c-1 -a 94 -t "Recorded"', shell=True)
time.sleep(2)
Popen('sudo python /home/pi/menu.py dlTopSelect.mnu', shell=True)
sys.exit()
示例3: runMatch
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def runMatch(self,playerOne, playerTwo,gameSeed) :
try :
inline= Popen("./QtSpimbot -file "+playerOne+" -file2 "+playerTwo
+ " -randomseed "+gameSeed+ " -randommap -tournament -run -exit_when_done -maponly -quiet ",\
stdout=PIPE, shell=True).stdout
string = "not"
while(not (string == '')) :
string = inline.readline()
if string[:7] == "winner:" :
return string[8:-1]
print "\nerror, What? This should not be so? Did you quit qtSpim?"
return self.manual_override(playerOne,playerTwo,gameSeed)
except KeyboardInterrupt:
return self.manual_override(playerOne,playerTwo,gameSeed)
except Alarm:
print "timeOut"
killerror= Popen("killall QtSpimbot", stdout=PIPE, shell=True).stdout
print killerror.read()
time.sleep(1)
return "#fail#"
示例4: __init__
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def __init__(self, setupsDir=DEFAULT_SETUPS_DIR):
# initial setup of ups itself:
os.environ['UPS_SHELL'] = 'sh'
# initial setup of ups itself:
os.environ['UPS_SHELL'] = 'sh'
if POPEN_AVAILABLE:
f = Popen('. %s/setups.sh; ' % setupsDir + \
'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";',
shell=True,
stdout=PIPE).stdout
else:
f = os.popen('. %s/setups.sh; ' % setupsDir + \
'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";')
exec f.read()
f.close()
# we need to initialize the following so that we can
# make the correct changes to sys.path later when products
# we setup modify PYTHONPATH
self._pythonPath = os.environ.get('PYTHONPATH', '')
self._sysPath = sys.path
(self._internalSysPathPrepend, self._internalSysPathAppend) = self._getInitialSyspathElements()
示例5: getPkgAct
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def getPkgAct(self, path):
#Use aapt to fetch pakage name and main activity from apk file
stdout = Popen(config.aapt+' dump badging '+path+' | awk -F" " \'/package/ {print $2}\'|awk -F"\'" \'/name=/ {print $2}\'', shell=True, stdout=PIPE).stdout
pkg = stdout.read()
stdout = Popen(config.aapt+' dump badging '+path+' | awk -F" " \'/launchable-activity/ {print $2}\'|awk -F"\'" \'/name=/ {print $2}\'', shell=True, stdout=PIPE).stdout
act = stdout.read()
return pkg, act
示例6: check
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def check(self, logger, agentConfig):
"""Return a dictionary of metrics
Or False to indicate that there are no data to report"""
logger.debug('Cassandra: start')
try:
# How do we get to nodetool
nodetool = agentConfig.get("cassandra_nodetool", None)
if nodetool is None:
return False
else:
if not os.path.exists(nodetool) or not os.path.isfile(nodetool):
logger.warn("Cassandra's nodetool cannot be found at %s" % (nodetool,))
return False
# Connect to what?
cassandra_host = agentConfig.get("cassandra_host", None)
if cassandra_host is None:
if nodetool is not None:
cassandra_host = "localhost"
logger.info("Nodetool is going to assume %s" % (cassandra_host))
else:
return False
# A specific port, assume 8080 if none is given
cassandra_port = agentConfig.get("cassandra_port", None)
if cassandra_port is None:
if nodetool is not None:
cassandra_port = 8080
logger.info("Nodetool is going to assume %s" % (cassandra_port))
else:
return False
nodetool_cmd = "%s -h %s -p %s" % (nodetool, cassandra_host, cassandra_port)
logger.debug("Connecting to cassandra with: %s" % (nodetool_cmd,))
bufsize = -1
results = {}
# nodetool info
pipe = Popen("%s %s" % (nodetool_cmd, "info"), shell=True, universal_newlines=True, bufsize=bufsize, stdout=PIPE, stderr=None).stdout
self._parseInfo(pipe.read(), results, logger)
logger.debug("Cassandra info: %s" % results)
pipe.close()
# nodetool cfstats
pipe = Popen("%s %s" % (nodetool_cmd, "cfstats"), shell=True, universal_newlines=True, bufsize=bufsize, stdout=PIPE, stderr=None).stdout
self._parseCfstats(pipe.read(), results)
pipe.close()
# nodetool tpstats
pipe = Popen("%s %s" % (nodetool_cmd, "tpstats"), shell=True, universal_newlines=True, bufsize=bufsize, stdout=PIPE, stderr=None).stdout
self._parseTpstats(pipe.read(), results)
pipe.close()
return results
except Exception, e:
logger.exception(e)
return False
示例7: get_versions
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def get_versions():
""" Try to find out the versions of gcc, ld and dllwrap.
If not possible it returns None for it.
"""
from distutils.version import LooseVersion
from distutils.spawn import find_executable
import re
gcc_exe = os.environ.get('CC') or find_executable('gcc')
ld_exe = find_executable('ld')
out = Popen(gcc_exe+' --print-prog-name ld', shell=True, stdout=PIPE).stdout
try:
ld_exe = str(out.read()).strip()
finally:
out.close()
if gcc_exe:
out = os.popen(gcc_exe + ' -dumpversion','r')
out_string = out.read()
out.close()
result = re.search('(\d+\.\d+(\.\d+)*)',out_string)
if result:
gcc_version = LooseVersion(result.group(1))
else:
gcc_version = None
else:
gcc_version = None
if ld_exe:
out = os.popen(ld_exe + ' -v','r')
out_string = out.read()
out.close()
result = re.search('(\d+\.\d+(\.\d+)*)',out_string)
if result:
ld_version = LooseVersion(result.group(1))
else:
ld_version = None
else:
ld_version = None
dllwrap_exe = os.environ.get('DLLWRAP') or find_executable('dllwrap')
if dllwrap_exe:
out = os.popen(dllwrap_exe + ' --version','r')
out_string = out.read()
out.close()
result = re.search(' (\d+\.\d+(\.\d+)*)',out_string)
if result:
dllwrap_version = LooseVersion(result.group(1))
else:
dllwrap_version = None
else:
dllwrap_version = None
return (gcc_version, ld_version, dllwrap_version)
示例8: checkTor
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def checkTor(self):
stdout = Popen('ps aux | grep torrc | grep -v grep', shell=True, stdout=PIPE).stdout
stdout = str(stdout.read()).replace("b''",'')
if stdout != '':
return 1
else:
return 0
示例9: _get_fields
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def _get_fields(self, msg_path, length=50):
cmd = [
'mu',
'view',
msg_path,
'--summary-len=5',
'--muhome=%s' % config.HIPFLASK_FOLDERS['mu']
]
p = Popen(cmd, stdout=PIPE).stdout
fields = p.read().splitlines()
p.close()
message = {}
for field in fields:
separator = field.find(':')
if separator == -1:
continue
key = field[0:separator].lower()
value = field[separator+2:]
if len(value) > length:
value = value[:length] + '...'
message[key] = value
return message
示例10: _inhaleresults
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def _inhaleresults(self, cmd):
if POPEN_AVAILABLE:
p = Popen(cmd, shell=True,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
(stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
else:
(stdin,stdout,stderr) = os.popen3(cmd)
try:
filename = stdout.read()
filename = filename[0:-1]
if (filename == "/dev/null"):
msg = stderr.read()
raise upsException(msg)
finally:
stdin.close()
stdout.close()
stderr.close()
cutHere = '--------------cut here-------------'
setup = open(filename, 'a')
setup.write(self._getNewPythonEnv(cutHere))
setup.close()
if POPEN_AVAILABLE:
f = Popen("/bin/sh %s" % filename,
shell=True, stdout=PIPE).stdout
else:
f = os.popen("/bin/sh %s" % filename)
c1 = f.read()
f.close()
(realUpsStuff, ourOsEnvironmentStuff) = re.split('.*%s' % cutHere, c1)
#print("ourOsEnvironmentStuff = %s" % ourOsEnvironmentStuff)
exec ourOsEnvironmentStuff
示例11: check_noun
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def check_noun(sentence):
os.popen("echo " + sentence + " > C:\IRProject\stanfordtemp.txt")
stdout = Popen("C:\IRProject\god.bat", shell=True, stdout=PIPE).stdout
output = stdout.read()
output1 = re.findall(r"[\w']+", output)
words = sentence.split(".")[0].split()
count = 0
sent_position = 0
answer = {}
for s in words:
for o in range(count + 1, len(output1)):
if output1[o] != "ROOT" and s == output1[o]:
if output1[o - 1] == "NN" or output1[o - 1] == "NNS":
if s in list_of_related_terms:
adj = getNounAdj(s, sent_position)
answer[sent_position] = [s, adj]
if output1[o - 1] == "NNP" or output1[o - 1] == "NNPS":
adj = getNounAdj(s, sent_position)
answer[sent_position] = [s, adj]
count = count + 1
break
count = count + 1
sent_position = sent_position + 1
return answer
示例12: applicationCollectMac
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def applicationCollectMac(): #Developed the OS X function first because I have a Mac!
appArray = []
# Execute system profiler
appCollect = Popen (["system_profiler", "-detailLevel", "full", "SPApplicationsDataType", "-xml"], stdout = PIPE).communicate()[0]
# appCollect = open("platform_sample_files/osx_sample_system_profiler_output.xml") # Run sample profiler output as the system_profileer command is a little slow
xmlApp = appCollect.read()
xmlTree = etree.parse(StringIO(xmlApp))
xmlContext = etree.iterparse(StringIO(xmlApp))
xmlRoot = xmlTree.getroot()
for eachItem in xmlRoot: # This cascade isn't pretty and needs cleanup!
for eachItem in eachItem:
for eachItem in eachItem:
for eachItem in eachItem:
if eachItem.tag == "dict":
appDict = {}
for eachItem in eachItem:
if eachItem.tag == "key":
tagKey = eachItem.text
else:
tagText = eachItem.text
try:
if tagText and tagKey:
appDict[str(tagKey)]= str(tagText)
except:
pass
appArray.append(appDict)
return appArray
示例13: dependencies
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def dependencies(sentence):
os.popen("echo " + sentence + " > C:\IRProject\stanfordtemp.txt")
stdout = Popen("C:\IRProject\god.bat", shell=True, stdout=PIPE).stdout
output = stdout.read()
output1 = re.findall(r"[\w']+", output)
# print output1
sentence_split = sentence.split(".")[0].split()
count1 = 0
count = 0
for s in sentence_split:
depen[count1] = [s, {}]
for o in range(count, len(output1)):
if output1[o] == s:
break
count = count + 1
count1 = count1 + 1
count = count + 1
for o in range(0, count):
if output1[o] in sentence_split:
sentence_POS[output1[o]] = output1[o - 1]
for o in xrange(count, len(output1) - 1, 5):
if output1[o] != "root":
if output1[o] == "neg":
negations[int(output1[o + 2]) - 1] = output1[o + 1]
try:
depen.get(int(output1[o + 2]) - 1)[1][int(output1[o + 4]) - 1] = output1[o + 3]
depen.get(int(output1[o + 4]) - 1)[1][int(output1[o + 2]) - 1] = output1[o + 1]
except:
return {}
return depen
示例14: executeCommandAndArguments
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def executeCommandAndArguments(caa, dumpfilepath):
result = Popen(caa, stdout=PIPE).stdout
dumpfile = open(dumpfilepath, 'w')
dumpfile.write( result.read() )
dumpfile.close()
result.close()
示例15: git_version
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import read [as 别名]
def git_version(path):
from subprocess import Popen, PIPE, STDOUT
cmd = 'git --git-dir=' + path + '.git log --pretty=format:%h -n1'
p = Popen(cmd, shell=True, stdout=PIPE).stdout
version = p.read()
p.close()
return version