Skip to content Skip to sidebar Skip to footer

Python: Return Output Of Ksh Function

On Unix, how can Iretrieve the output of a ksh function as a Python variable? The function is called sset and is defined in my '.kshrc'. I tried using the subparser module accordi

Solution 1:

shlex is not doing what you want:

>>> list(shlex.shlex("/bin/ksh -c \". /Home/user/.khsrc\""))
['/', 'bin', '/', 'ksh', '-', 'c', '". /Home/user/.khsrc"']

You're trying to execute the root directory, and that is not allowed, since, well, it's a directory and not an executable.

Instead, just give subprocess.call a list of the program's name and all arguments:

importsubprocesscommand_line= ["/bin/ksh", "-c", "/Home/user/.khsrc"]
subprocess.call(command_line)

Post a Comment for "Python: Return Output Of Ksh Function"