我想将文本添加到只能从特定帐户ID“appid”和passwd“passx”访问的文件中 我试过下面的代码,不行。在Python中运行已更改(已切换)用户的命令行脚本
import os, subprocess
text=str('23.33%')
cmd = ['su', 'appid', '-c echo text >> /tofhisfile.txt']
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.communicate('passx')
也
os.system('su appid -c echo text >> /tothisfile.txt')