Newbie Alert: subprocess.call

Patrick Maupin pmaupin at gmail.com
Wed May 19 22:38:07 EDT 2010


On May 19, 9:27 pm, Carbon <nob... at nospam.tampabay.rr.com> wrote:
> I am new to Python and am trying to write a GUI wrapper script in python
> 2.5 to get username and passwords from Linux users to send as options to
> run an app on a 2X terminal server. I came across the easygui module and
> its multpasswordbox function, which made popping a dialog box and storing
> the usernames very painless.
>
> However, subprocess.call as implemented below doesn't work. For some
> reason the "-s ts.mycompany.org:80" parameter is being interpreted
> differently by the application when sent from the python script than it
> does when sent from the BASH script below. The :80 is the default port so
> it isn't technically required, but the script doesn't work without it
> either.
>
> Any ideas where I should look? Is subprocess.call the best way to do what
> I want? Any advice would be most appreciated.
>
> Here's the broken bit:
>
> print "Reply was:", fieldValues
> print "Reply was:", fieldValues[0], fieldValues[1]
>
> subprocess.call(["/opt/2X/Client/bin/appserverclient", "-u fieldValues
> [0]", "-p fieldValues[1]", "-s ts.mycompany.org:80", "-d corp", "-S
> local", "-c 16", "-e 0xF", "-l 0x0409", "-a #1"])
>
> Output:
>
> me at work:~/bin$ ./demo2.py
> Reply was: ['MyUsername', 'MyPassword']
> Reply was: MyUsername MyPassword
>
> ERROR in CTcpConnector:  ts.mycompany.org: unable to resolve host
> Error 7: TCP/IP connection: unable to resolve host.
>
> This BASH script runs correctly:
> me at work:~/bin$ cat 2xconnect
> #!/bin/bash
>
> USER=$1
> PASS=$2
>
> /opt/2X/Client/bin/appserverclient \
> -u "$USER" \
> -p "$PASS" \
> -s ts.mycompany.org:80 \
> -d corp \
> -S local \
> -c 16 \
> -e 0xF \
> -l 0x0409 \
> -m 2G \
> -a "#1"

I think, for example, instead of "-d corp", you want "-d" and "corp"
in your list.

I usually make a string like I would pass to bash, and then
do .split() on it to get the list.  This works fine unless you need
embedded spaces anywhere.

Regards,
Pat



More information about the Python-list mailing list