I want to split a new empty disk using a Python script on Ubuntu.
In a bash script or from the command line, this will do the job:
$echo -e "n\np\n1\n\n\nw\n" | sudo fdisk /dev/X
where X is the hard drive.
I tried porting this to a Python script using the subprocess module as follows:
p = subprocess.Popen(cmdString, stdout=subprocess.PIPE, \ close_fds=False, stderr=subprocess.PIPE,shell=True) stdoutAndErr = p.communicate()
where cmdString is the same line of "echo -e ..." above.
This does not work. The output is just fdisk printing the command parameters, so he clearly doesn't like the fact that I'm sending it.
What is wrong with the above simple approach to life?
python subprocess ubuntu
liamf
source share