Using os.system() and string concatenation

Wayne Witzel III wwitzel3 at gmail.com
Sun Oct 17 14:24:16 EDT 2004


Actually found the problem. The editor he was using had a bug in it's
Python syntax highlighting and was placing weird tab sequences when
you saved.

Wayne

On Tue, 12 Oct 2004 23:11:13 +0100, Michael Hoffman
<m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> wrote:
> Wayne Witzel III wrote:
> > os.system("/usr/sbin/useradd"+ " -d " + user[0] + " -s " + user[1] + "
> > " + user[3])
> >
> > when I change os.system() to print .. it outputs just fine and I can
> > copy and paste the results and they execute. Just using os.system()
> > they do not execute unless I place the string in cmd variable first.
> >
> > cmd = "/usr/sbin/useradd"+ " -d " + user[0] + " -s " + user[1] + " " + user[3]
> > os.system(cmd)
> >
> > This works fine.
> 
> This is very odd, Wayne, and somewhat unexpected. What happens if you
> replace /usr/sbin/useradd with /bin/echo (or wherever your echo command is):
> 
>  >>> import os
>  >>> user = ["foo", "bar", "baz", "moo"]
>  >>> os.system("/bin/echo"+ " -d " + user[0] + " -s " + user[1] + " " +
> user[3])
> -d foo -s bar moo
> 0
>  >>> cmd = "/bin/echo"+ " -d " + user[0] + " -s " + user[1] + " " + user[3]
>  >>> os.system(cmd)
> -d foo -s bar moo
> 
> As others have said, os.spawnv() is probably a better choice anyway...
> --
> Michael Hoffman
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list