* TypeError - Need help passings args

Discussion in 'Python' started by Ernesto, Nov 2, 2005.

  1. Ernesto

    Ernesto Guest

    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/Cookbook/Python/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)
     
    Ernesto, Nov 2, 2005
    #1
    1. Advertising

  2. Ernesto

    Juho Schultz Guest

    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/Cookbook/Python/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.
     
    Juho Schultz, Nov 2, 2005
    #2
    1. Advertising

  3. Ernesto

    Ernesto Guest

    Re: * TypeError - Need help passings args

    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.
     
    Ernesto, Nov 2, 2005
    #3
  4. Ernesto

    Juho Schultz Guest

    Re: * TypeError - Need help passings args

    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.
     
    Juho Schultz, Nov 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    658
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    538
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    752
    Pierre Fortin
    Sep 18, 2004
  4. Holger
    Replies:
    42
    Views:
    974
    Holger
    May 8, 2006
  5. er
    Replies:
    2
    Views:
    541
Loading...

Share This Page