Using dd command through Python subprocess module
Through the Python subprocess module, I am trying to capture the output of the dd command. Here's a snippet of code:
r = subprocess.check_output(['dd', 'if=/Users/jason/Desktop/test.cpp', 'of=/Users/jason/Desktop/test.out'])
however, when I do something like
print r
I am getting an empty string.
Is there a way to capture the output of the dd command into some kind of data structure so that I can access it later?
Basically I want the below result to be stored in a list so that I can perform operations on the number of bytes later on.
1+0 records in
1+0 records out
4096 bytes transferred in 0.000409 secs (10011579 bytes/sec)
+3
source to share
1 answer
dd
doesn't output anything to stdout, so your result is correct. However, it does output to stderr. Go to stderr=subprocess.STDOUT
to get stderr output:
>>> o = subprocess.check_output(
['dd', 'if=/etc/resolv.conf', 'of=r'], stderr=subprocess.STDOUT)
>>> print(o)
b'0+1 records in\n0+1 records out\n110 bytes (110 B) copied, 0.00019216 s, 572 kB/s\n'
+5
source to share