How to running dd command in python for windows

Question:

[Solved]
I found the method finally…, I’ve updated the solution here, hope it can helps someone who need.

Download the dd file for windows first, http://www.chrysocome.net/dd, after unzip, put the dd.exe into python scripts file, then, it’s works!!


I would like to excute dd command in python but it doesn’t works, the error is "’dd’ is not recognized as an internal or external command", but it’s works in cmd on windows.
I was try but cann’t find similar module or function, could anyone help me? Thanks!

Below is my code.

def dd_cmd():
   ddfile = open('dd_test.txt','w')
   ddcmd = ["dd", "if=d:/tartest/config-5w20.txt", "of=d:/tartest/config-5w20a.txt", "bs=1", "count=36", "status=progress"] 
   d = subprocess.Popen(ddcmd,stdout=ddfile, stderr=ddfile)
   d.wait()

if __name__ == '__main__':
   dd_cmd()
Asked By: WCJ

||

Answers:

There isn’t any official dd command for Windows. You can use an alternative.
Download it first, then run your code easily.


Hint

You should put the executable file next to other files of your project
Or
Put the executable file anywhere you want and update Path Environment

Answered By: Arash Hatami
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.