Reputation: 1529
cmd_a = "a\n{0}\nt\n{0}\nda\nw\n".format(number)
cmd_b = subprocess.Popen("fdisk %s" % file_name, shell=True,stdin=subprocess.PIPE)
fdisk_cmd.communicate(cmd_a)
This code works with Python2.x but on Python3.x it gives me:
File "bootimage.py", line 44, in do_install_file
| fdisk_cmd.communicate(cmd_a)
| File "/usr/lib/python3.4/subprocess.py", line 930, in communicate
| self.stdin.write(input)
| TypeError: 'str' does not support the buffer interface
Upvotes: 2
Views: 1374
Reputation: 140196
In python 3, subprocess
streams are binary.
To write a string, just encode a binary, in your case ascii
codec is OK:
fdisk_cmd.communicate(cmd_a.encode("ascii"))
Upvotes: 5