close
在python中 , 我們可以藉由strip()來去掉字串頭尾的空白,
for example:
def execSystemCmd(cmd):
proc = subprocess.Popen([cmd],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output = proc.stdout.read()
os.wait()
return output
infors=str(execSystemCmd('cat /etc/hosts')).strip()
會將回傳字串的頭尾空白去除掉.
全站熱搜