Using os.system() and string concatenation

Wayne Witzel III wwitzel3 at gmail.com
Tue Oct 12 16:44:51 EDT 2004


On Tue, 12 Oct 2004 20:15:57 +0000 (UTC), Steven Bethard
<steven.bethard at gmail.com> wrote:
> Wayne Witzel III <wwitzel3 <at> gmail.com> writes:
> 
> > No, I was properly inserting the spaces. When I changed it to a print
> > statement and executed the resulting output, it worked just fine.
> 
> Not sure if I understand exactly what you said here, but just to be clear, the
> print statement inserts spaces:
> 
> >>> x, y, z = 'x', 'y', 'z'
> >>> print x, y, z
> x y z
> >>> x + y + z
> 'xyz'
> >>> print x + y + z
> xyz
> >>> import sys
> >>> sys.stdout.write(x + y + z)
> xyz
> 
> So if you're saying the output of a print statement works, but the string
> concatenation doesn't then yes, it does sound like you're not inserting spaces.
> 

Ok, here is what I had.

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.

It was not a white space issue. Since I copied the exact string
between () and pasted it to the variable and it worked.



More information about the Python-list mailing list