[英]Why does "dd" in a python subprocess write no bytes to STDOUT?
我想將“dd”命令的輸出重定向到我的 python 腳本中的 stdout。 這是我的代碼:
def dd2pipe():
chunk=654321
skip_ntimes= 2
read_ntimes= 3
filepath='39476a90-a5f1-cd59-7a8d-34c016276514.high.mp3'
p1_cmds = [f'dd bs={chunk}',
f'skip={skip_ntimes}',
f'count={read_ntimes}',
f'if={filepath}']
p1 = sp.Popen(p1_cmds,shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
byte_data= p1.stdout.read()
p1.stdout.close()
p1.wait()
print(byte_data)
dd2pipe()
我得到的輸出是:
b'0+0 records in\n0+0 records out\n0 bytes copied, 2,338e-05 s, 0,0 kB/s\n'
你能幫我讀取 STDOUT 中 dd 命令的字節嗎?
感謝 Ry-s 的回答,它有效。 我將 shell 更改為 False 並將 p1_cmds 更改為:
p1_cmds = ['dd',
f'bs={chunk}',
f'skip={skip_ntimes}',
f'count={read_ntimes}',
f'if={filepath}']
p1 = sp.Popen(p1_cmds,shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.