Using os.system() and string concatenation

Fredrik Lundh fredrik at pythonware.com
Tue Oct 12 21:02:53 CEST 2004


Wayne Witzel III wrote:

> Currently I process three files and build the output of those files in
> to lists using for statements.
>
> I think take those lists and provide them to an os.system() call.
>
> cmd = "/usr/sbin/useradd"
> os.system(cmd + list1[0] + list1[1] + list2[0] + list3[0])
>
> This executes without any errors, but doesn't execute the command
> supplied to os.system(). Now if I place them all in cmd first, then
> supply it to os.system() it executes just fine. So there really isn't
> a problem, just wanting to know what would cause such behavior.

the + sign doesn't add a space, so you're probably trying to execute
"/usr/sbin/useraddsomethingsomethingsomethingsomething" instead of
"/usr/sbin/useradd something something something something".

</F> 






More information about the Python-list mailing list