Sending a picture file as a parameter to start a program

I am looking to create a temporary picture viewer for at work, hopefully using JME, and I have stumbled upon a problem.



This picture viewer would need to be supplied a loaded image file at startup, but how do I supply this image file to my applet or executable jar or whatever at the program startup for it to process??



I would really appreciate any help with this question because it is this problem that will make it possible for us to accomplish this project or not.



Thanks!

You can open a file with a java application in the same way you can do that with any other kind of program: the file path will be passed to the program as a component of the String's array of the main method.



Also, if I remember well, a Java Web Start descriptor has an option to create a custom file association but you can do the same with the desktop manager (both in windows and linux and i think in OSx too)



In the end it will work as if you start the program with the command:



java -jar MyAppJar.jar [file path]

The input stream case is way more interesting  :slight_smile: Basically it's inter process communication. A "command line example" could be this:



java -jar MyApp.jar | java -jar MyApp2.jar



What happens is that the output stream of the process on the left is chained with the input stream of the process on the right. In Java this means that the System.out of the first program "writes" to the System.in of the second program.



So instead of taking a value from the array of strings of the main method you read bytes from System.in (in MyApp2).



It's more or less the same we do when we call:



Process x = ProcessBuilder create some process

x.getInputStream().write(a byte)



we have one process that starts another process and communicates with it via standard input / output.



The | chaining is just a simple example. It would be probably better to use a socket to send data to the second program: you implement the program as a system service listening to a local port and other programs send data to that address.

+1 for using a service with sockets.


pgi said:
The | chaining is just a simple example. It would be probably better to use a socket to send data to the second program: you implement the program as a system service listening to a local port and other programs send data to that address.


It sounds more like you would have the service listening on external ports for a command (or the actual inputstream) from the server which triggers the viewer application to wakeup and receive the incoming inputstream over a local socket.

Only problem is that if its meant for consumers, then you can't assume they'll have the savvy to open ports on their router for the listener.  You can overcome this by trying (good luck ^^) the PPTP route or by setting up that listener service as one that pings the server every so often to ask for an inputstream..

Sadly to say, when the specifications for this image viewer came, it would need to load tiff files, so sadly this ruled the option of making a temporary inhouse image viewer out of the question (as JME was our most likely candidate for such a development)



however, this discussion has been quite interesting :slight_smile: Thanks everyone!

Java loves tiffs and JME2 can freely use them. It's just a matter of adding two jars and one native library to the program's path:



https://jai-imageio.dev.java.net/binary-builds.html



Magics of ImageIO.