我想通过python脚本格式化一个硬盘子流程.Popen. 在shell中输入以下命令很好。注意这个命令!在
parted /dev/sdh mklabel gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No?
我同意输入Yes,磁盘格式化良好。在
在Python子进程中滚动它,Popen退出,状态代码为1。 我甚至不能在stdin管道中写“Yes”。在
代码如下:
^{pr2}$1
或者
# test2
p = Popen('parted /dev/sdh mklabel gpt', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
p.stdin.write('Yes\n')
IOError:[Errno 32]管道破裂
我不确定波本是否认为这一警告是错误的,如果是这样,我该如何改变他的行为? 谢谢你的建议。在
通过在命令中添加-s选项(忽略输出),parted成功退出。在
相关问题 更多 >
编程相关推荐