[ubuntu-us-in] hard drive tools* ssh ftp suggestions
Rob Ludwick
rob at rcludw.no-ip.org
Sun May 4 05:03:33 BST 2008
> Of course a neat trick in python is to use popen2() and use dd without
> an "of" paramter. dd sends the data to standard out, which in python
> through popen2() becomes a file. (Yay!) You know how many bytes you
> get because you you can count them and you would get an EOF before you
> were done reading blocksize. At this point you would adjust your dd
> parameters to start at the next 512 byte block on the drive. And then
> you can just use python to interleave the 4k blocks.
This runs dd in popen.
#!/usr/bin/env python
import popen2
inputfile = "/dev/zero"
outputfile = "/tmp/test"
bs=2**16
dd = "dd if=" + `inputfile` + " bs=" + `bs` + " count=1"
file = open(outputfile, "w")
(outfd, infd) = popen2.popen2(dd)
buf=outfd.read()
if len(buf) != bs:
print "error."
else:
print "success!"
file.write(buf)
file.close()
infd.close()
outfd.close()
More information about the Ubuntu-us-in
mailing list