[QUOTE=dgovil;17289]Hey Theodox, man the stdout actually works great.
The stdin part hangs, because I assume it’s waiting for the python process to finish before it will give user back control.
(also sorry for the delayed response…got caught up in a lot of other things )
Cheers. I’m going to keep trying for better integration. Thank you.[/QUOTE]
Hanging is what I’d expect – python is waiting for some kind of input from the program that fired the python off in the first place. Unless the hosting program has something like a named pipe connection to your python, nothing will ever be input.
Since you have the ability to start a new python, you can pass it arguments and get at those with sys.argv – that would let you fire the python instance from the main app, process the arguments, and print out the results or do something based on the args before returning control to the main app. You won’t be able to ‘interactively’ control python, though, unless the main app can write to what python thinks of as stdin – which is unlikely to be a ‘free’ feature in your main app.
If your python looks like this:
import sys
if __name__ == '__main__':
args = sys.argv
for item in args:
print 'got', item # I'm guessing that in your context this and sys.stdout.write are interchangeable.....
and your app calls:
run python "myscript.py" "string" "number"
you should get back
got myscript.py
got string
got number
(argv[0] is the script passed in)
Presumably you could get some functionality out of it this way – but you’ll have significant startup costs, since each exchange between the main app and python will start a new python instance – you won’t be able to persist it between invocations, since it won’t return data to the main app until it exits. However the python instance can talk to outside stuff and summarize results for the main app – for example, you could talk to an always-on server (maybe another python app running RPyC or a web service running on your machine) via http and return the results to your app that way:
(App) >>> (run myscript.py arg arg arg) >> RPC call >> (server “<dosomething><arg><arg><arg><dosomething>”) >> back to myscript as XML >> back to App as text