我的脚本在最新升级后似乎停止工作。为了找到问题,我写了一个小脚本:
import subprocess
hdparm = subprocess.Popen(["xargs","echo"],
stdin=subprocess.PIPE)
hdparm.stdin.write("Hello\n")
hdparm.stdin.write("\n")
hdparm.stdin.close()
hdparm.wait()
quit()
这只是打印“Hello”和一个新行,但我希望有两个换行符。这是什么原因造成的?(我目前使用的是 2.7.3)
编辑:这是有问题的脚本(为清楚起见进行了编辑):
hdparm = subprocess.Popen(["hdparm", "--please-destroy-my-drive", "--trim-sector-ranges-stdin", "/dev/sda"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
hdparm_counter = 0
for rng in ranges_to_trim:
hdparm.stdin.write("%d:%d\n" % (rng["begin"],rng["length"]))
hdparm_counter += 1
if hdparm_counter > 63:
hdparm.stdin.write("\n")
hdparm_counter = 0
if hdparm_counter != 0:
hdparm.stdin.write("\n")
hdparm.stdin.close()
hdparm.wait()
编辑:我相信问题出在我的脚本本身。我需要将 EOF 发送到 hdparm 以使其执行应有的操作。