“parted mklabel”通过Python子进程引发错误

2024-04-29 07:59:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过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]管道破裂

我不确定波本是否认为这一警告是错误的,如果是这样,我该如何改变他的行为? 谢谢你的建议。在


Tags: 代码dev命令onstdinbeshellwill