Using os.system() and string concatenation

Steven Bethard steven.bethard at
Tue Oct 12 20:57:06 CEST 2004

Wayne Witzel III <wwitzel3 <at>> writes:

> cmd = "/usr/sbin/useradd"
> os.system(cmd + list1[0] + list1[1] + list2[0] + list3[0])

Are you inserting spaces appropriately?  The code above makes one long command 
that looks like "usr/sbin/useraddoutput1output2output3output4".  Is this what 
you meant to do?

If not, you could try something like:

os.system(' '.join([cmd, list1[0], list1[1], list2[0], list3[0]]))

which should put spaces between the command and each of the entries...

If this is not what you're trying to do, could you give us a little more 
information on what the listi[j] things contain?  An example of what

print cmd + list1[0] + list1[1] + list2[0] + list3[0]

outputs would also be helpful.


More information about the Python-list mailing list