subprocess - How to communicate with parted interpreter via python? -


from subprocess import popen,pipe,stdout  a=popen('parted -s',stdout = pipe, stderr = stdout, shell = true) a.communicate(input="print".encode()) string=a.stdout.read() 

i want use "print" command within parted, how do so?

you can achieve without sending input child's stdin, use command line , execute subprocess.check_output():

import shlex import subprocess  device = '/dev/sda' cmd = 'parted -s {} print'.format(device)  output = subprocess.check_output(shlex.split(cmd))  >>> print output model: ata hitachi hts54756 (scsi) disk /dev/sda: 640gb sector size (logical/physical): 512b/4096b partition table: msdos disk flags:   number  start   end    size   type      file system  flags  1      1049kb  210mb  209mb  primary   ntfs         boot  2      210mb   322gb  322gb  primary   ntfs  4      322gb   640gb  318gb  extended  5      322gb   322gb  524mb  logical   ext4  6      322gb   640gb  318gb  logical                lvm  3      640gb   640gb  108mb  primary   fat32        lba 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -