我想將文本添加到只能從特定帳戶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')