Using os.system() and string concatenation
Wayne Witzel III
wwitzel3 at gmail.com
Tue Oct 12 22:44:51 CEST 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
> >>> print x + y + z
> >>> import sys
> >>> sys.stdout.write(x + y + z)
> 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 + " -s " + user + "
" + user)
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 + " -s " + user + " " + user
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