Request Help With Function

Wildman best_lay at yahoo.com
Mon Apr 4 15:42:45 EDT 2016


I am working on a Linux gui program where I want to be able
to click a Help button and open a man page using a viewer.
I wrote a search function that can be called several times,
if needed, with different arguments.  I wrote a test program
that tries to open the Bash man page in a terminal and will
display a message box if the search fails.  It passes the
system path, terminal emulators and command line arguments
to the search function.  I appears that you can't pass a list
to a function so I am passing the arguments as strings and then
converting them to lists for parsing in the search function.

When I run the test program, I get this error:

Traceback (most recent call last):
  File "./man.py", line 38, in <module>
    launch_help()
  File "./man.py", line 10, in launch_help
    if search(pathlist, executelist, commandlist):
  File "./man.py", line 27, in search
    subprocess.Popen(command)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
TypeError: execv() arg 2 must contain only strings

I have not been able to figure out why I'm getting the error.
Any help would be appreciated.  Below is the complete code for
the test program:

#!/usr/bin/env python

import os, subprocess, tkMessageBox

def launch_help():
    pathlist = os.environ["PATH"]
    executelist = "xvt,xfce4-terminal"
    commandlist = "-e,man bash"
    if search(pathlist, executelist, commandlist):
        return None
    message = "Open a terminal and enter:  man bash"
    tkMessageBox.showinfo("Help", message)

def search(pathlist, executelist, commandlist):
    pathlist = pathlist.split(":")
    executelist = executelist.split(",")
    commandlist = commandlist.split(",")
    done = False
    for path in pathlist:
        for execute in executelist:
            target = path + "/" + execute
            if os.path.isfile(target):
                done = True
                command = [target, commandlist]
                subprocess.Popen(command)
            if done:
                break
        if done:
            break
    if done:
        return True
    else:
        return False


launch_help()

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!



More information about the Python-list mailing list