JNLP File download and run

Michael Torrie torriem at gmail.com
Tue May 24 10:53:47 EDT 2016


On 05/24/2016 12:01 AM, Robert Clove wrote:
> Can u provide the pseudo code for the same

I think you'll be disappointed.  What you want to do is a simple,
three-step affair in pseudocode:

download the jnlp file
launch javaws to run the jnlp file
delete jnlp file

That *is* the pseudo code in its entirety.  What more are you expecting?
 Here's a simple, possibly naive, bash example:

#!/bin/bash
jnlp_file=$(mktemp tmpXXXXX.jnlp)
wget -O - "$1" > "$jnlp_file"
xdg-open "$jnlp_file"
rm -f "$jnlp_file"

On windows, python ships with a handy wrapper in the os module:
http://stackoverflow.com/questions/15054434/how-can-i-open-files-in-external-programs-in-python
.  With this is in mind, we could expand the pseudocode slightly to work
on multiple platforms:

jnlp_file = create a temporary filename with .jnlp extension
download jnlp_url and write it to jnlp_file

if on windows:
   os.startfile(jnlp_file)
elif on mac:
   execute "open" with the jnlp_file
elif on linux:
   execute "xdg-open" with the jnlp_file

delete  jnlp_file

Take a look at the urls I've found and you'll see how to use urllib and
also subprocess (or os.startfile) to do what you want to do, including
examples you can adapt.  Should be just a few of lines of actual python
code to start with.

> 
> On Fri, May 20, 2016 at 9:06 PM, Michael Torrie <torriem at gmail.com
> <mailto:torriem at gmail.com>> wrote:
> 
>     On 05/20/2016 01:30 AM, Robert Clove wrote:
>     > Hi,
>     >
>     > Can someone give me pseudo code to download and JNLP file from a URL and
>     > run it?
>     >
>     > Looks like a advance concept in python
> 
>     You could use the urllib module to download the file, then use the
>     subprocess module to spawn the javaws executable and pass it the
>     location of the jnlp file as a parameter.
> 
>     https://docs.python.org/3.6/howto/urllib2.html
>     https://docs.python.org/3.6/library/subprocess.html
> 
>     There are other ways besides launching javaws directly, such as asking
>     cmd.exe to invoke "start" and the jnlp file so that the default javaws
>     executable will run. On Mac there's the "open" binary that can do the
>     same thing, and on Linux, xdg-open.
> 
>     --
>     https://mail.python.org/mailman/listinfo/python-list
> 
> 




More information about the Python-list mailing list