tags:

views:

43

answers:

2

Hi, guys,

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 them 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)!!

A: 

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.

relima
HI, relima, thank you very much for your answer. If I use urllib2.urlopen("http://www.ABC.com/xxx.out") and tmpfile= NamedTemporaryFile(mode='w+b', suffix='.out', prefix='xxx', dir), but how to combine the two? to reach the goal "open the url, and download the file into the namedtempfile"?
pepero
A: 

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.

Santiago Lezica
HI, Santiago, for the 2nd scenario, it is the C++ source code and makefile of the program
pepero
Well, you can always make and run the program, but different problems may arise... why do you want that functionality?
Santiago Lezica