Python split and merge the line -
df = subprocess.popen(["df", options.partname], stdout=subprocess.pipe) output = df.communicate()[0] print output
gives following:
filesystem 1k-blocks used available use% mounted on /dev/mapper/sys-scratch 1446412616 847216452 524555652 62% /scratch
in cases (machines),
output.split("\n")[1]
gives me
/dev/mapper/sys-scratch
where want
/dev/mapper/sys-scratch 1446412616 847216452 524555652 62% /scratch # in 1 line
i using values in output :
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
for machines, fails because output.split("\n")[1]
has single value. how can fix ?
in specific case, can re-join 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()
Comments
Post a Comment