0
df = subprocess.Popen(["df", options.partname], stdout=subprocess.PIPE)
output = df.communicate()[0]
print output

gives the following:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/sys-scratch
                     1446412616 847216452 524555652  62% /scratch

In some cases (machines),

output.split("\n")[1] 

gives me

/dev/mapper/sys-scratch

where as I want

/dev/mapper/sys-scratch 1446412616 847216452 524555652  62% /scratch  # in one line

I am using the values in the output like this :

device, size, used, available, percent, mountpoint = output.split("\n")[1].split()

For some machines, this fails because output.split("\n")[1] only has a single value. How can I fix this ?

iamauser
  • 11,119
  • 5
  • 34
  • 52

1 Answers1

0

In this specific case, you can re-join the last 2 lines:

df = subprocess.Popen(["df", options.partname], stdout=subprocess.PIPE)
output = df.communicate()[0]
output = ' '.join(output.splitlines()[1:])
device, size, used, available, percent, mountpoint = output.split()
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343