call remote programs by URL with python
I am developing a GUI in python with wxPython framework to launch several subprocess programs. Now I could do it for the local files, e.g. if we have a compiled .out file under the path "/AAA/BBB/xxx.out", I could do with command like this:
subprocess.Popen("/AAA/BBB/xxx.out", stdout=subprocess.PIPE)
Now, I am thinking to develop the following two URL-related remote features, still calling th开发者_开发百科em as subprocesses (because the main process is the GUI), but I do not know how to do it in python.
1) how to launch the program, given the url of the .out file? e.g. given http://www.ABC.com/xxx.out
2) how to launch the program, given the url of the source code of this .out file (e.g. http://www.ABC.com/xxx/src/ contains the C++ source code and the makefile of the program)
what kind of python module could be used and what potential problems might be envolved? Usually what is the right way to implement these two features?
Thanks a lot for any suggestions or sample code (that will be very helpful)!!
For loading this online file as subprocess from within your program, you are going to have to download it for a temporary location. Just use urllib2 module to download the file together with http://docs.python.org/library/tempfile.html to create a temporary placeholder for it. They you can execute it.
There's two very separate parts to your question: how to get a file from a remote URL, and how to execute it.
You seem to have the first part covered, so just google how to download files with Python. You can also use an already existing file downloader for the task (you already have the executing subprocesses part done), or better still, an existing Python module.
Now, given the URL of a source code,... source code of what? I mean, if it's python, you can run it in an interpreter, but you may need to compile source code in other languages, and that may have dependencies, and other complications.
精彩评论