468,301 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

* TypeError - Need help passings args

My program is below. I'm trying to use two Windows ".exe" files with
my command line python interface. I get user input, then call
"launchWithoutConsole". This was working OK until I introduced the
'args' part. Now I get the following error everytime I call
"launchWithoutConsole":

return subprocess.Popen([command] + args,
startupinfo=startupinfo).wait()

TypeError: can only concatenate list (not "str") to list

I'm not sure if it's the WAY I'm passing it or if it's the function
itself (which I retrieved from
http://aspn.activestate.com/ASPN/Coo.../Recipe/409002
)

Please help. Thanks!

import subprocess

def launchWithoutConsole(command, args):
"""Launches 'command' windowless and waits until finished"""
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return subprocess.Popen([command] + args,
startupinfo=startupinfo).wait()

infinity = 1
#Get user input in iterative loop
while infinity:
userCommand = raw_input("> ")
if userCommand == "connect":
launchWithoutConsole("devcon.exe",'enable
"@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000 ')
launchWithoutConsole("devcon.exe",'enable
"@USB\VID_0403&PID_6010&MI_01\7&15E4F68&1&0001 ')
elif userCommand == "disconnect":
launchWithoutConsole("devcon.exe",'disable
"@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000 ')
launchWithoutConsole("devcon.exe",'disable
"@USB\VID_0403&PID_6010&MI_01\7&15E4F68&1&0001 ')
else:
# include full path to rib.exe in quotes.
launchWithoutConsole("rib.exe", userCommand)

Nov 2 '05 #1
3 1998
Ernesto wrote:
My program is below. I'm trying to use two Windows ".exe" files with
my command line python interface. I get user input, then call
"launchWithoutConsole". This was working OK until I introduced the
'args' part. Now I get the following error everytime I call
"launchWithoutConsole":

return subprocess.Popen([command] + args,
startupinfo=startupinfo).wait()

TypeError: can only concatenate list (not "str") to list

I'm not sure if it's the WAY I'm passing it or if it's the function
itself (which I retrieved from
http://aspn.activestate.com/ASPN/Coo.../Recipe/409002
)

Please help. Thanks!

[command] is a list. So also "args" should be a list,
otherwise [command] + args produces an error.
Add a few square brackets to the calls, just like in the link.
Nov 2 '05 #2
Thanks, that ran without errors. The only problem now is that it
launches devcon.exe without actually passing the parameters to the
program. It's as if I just typed "devcon" at a Windows command prompt
and pressed enter. I can't figure out why it doesn't accept my
parameter.

Nov 2 '05 #3
Ernesto wrote:
Thanks, that ran without errors. The only problem now is that it
launches devcon.exe without actually passing the parameters to the
program. It's as if I just typed "devcon" at a Windows command prompt
and pressed enter. I can't figure out why it doesn't accept my
parameter.

I run python 2.3 on Linux os subprocess module and Windows executables
are not too familiar to me. But according to docs subprocess.Popen()
should accept both list and string arguments.

Your strings have backslashes so check docs.python.org/ref/strings.html

a = 'disable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000 '
print a
disable "@USB\VID_0403&PID_6010&MI_00&15E4F68&1&0000

\7 is the ASCII bell so your args may be different from what you think.
Nov 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Achim Domma | last post: by
reply views Thread by Michael Spencer | last post: by
7 posts views Thread by 5HH575-UAZWKVVP-7H2H48V3 | last post: by
6 posts views Thread by Mike Brown | last post: by
8 posts views Thread by Andi Clemens | last post: by
2 posts views Thread by Iain Adams | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.