We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My question is a bit more complicated than the title, but please bear with me.
I created a test sketch in Processing using this code:
void setup(){
String home = javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
PrintWriter out = createWriter(home + "\\out.txt");
out.println("Testing...");
try{
if(args.length > 0){
out.println(args[0]);
out.print("Input:\t");
out.println(loadStrings(args[0])[0]);
}
}catch(NullPointerException ne){
out.println("NullPointerException");
}catch(Exception e){
out.println("Error:\t" + e.getLocalizedMessage());
}
out.flush();
out.close();
exit();
}
After I exported the application as a .exe, I tried to set it as the default application for opening .test files. All was fine as long as the input file(with .test extension) was in the same folder as the .exe exported by Processing. But when I shifted the input outside the same folder, it stopped working all together. Please help me.
One more thing - does anyone know how to programatically set the .exe as the default application for opening .exe files(Only for Windows)? Thanks!
Answers
I do not know about windows, but when you open a file in Unix it passes it as an argument to the program. I would like to know if it is possible to handle arguments in processing like:
https://forum.processing.org/two/discussion/6457/how-to-use-arguments-with-an-application-built-with-processing
For instance:
Then you can export your application and run the executable in Windows via command prmpt. If you run your executable with any args, the code above will work and display the first one in the title (Tested).
Kf
I tried that already. As long as I open it using the command line the arguments are passed.
The problem is this - lets say I want to make a processing app and make it the default application for opening .jpg files. Now if I right click on a .jpg image -> open with ... -> Name of the Processing application (the .exe) then no arguments are passed to setup. On the other hand if I choose open with ... -> Notepad++, then Notepad++ opens the JPEG image
Yes, I tried and I couldn't make it work unless...
I created an empty file and I named it
fakedoc.fak
. I associated this file to my exported sample app that I specified above. I associated this type of files to my exported application. If this .fak file was located in My Documents folder or Downloads (for instance) it doesn't work when I tried the Open with.... I then try to run under the command prompt. The only way to run the executable is to cd to your folder containing your exported executable, then provide the absolute path to your fakedoc.fak file.That worked when ran under the command prompt. Then I thought about including the .exe file in the PATH system variable. However, the problem is that the exe file also needs to access the lib folder created by the export process. I tested this bc removing the lib folder makes the .exe file not to execute. In fact, nothing happens when you call it from the command prompt.
One more thing. If you move the fakedoc.fak file to the same folder level as your exported exe file, and then you open an explore window and click on this
.fak
file, it works. So I conclude that the requirements areFor the former, one can use the PATH file. For the later, I have no idea...
I hope some other forum goers can provide their input.
Kf
Maybe instead of using the .exe I should try with the .jar directly? Not sure if it will work though
Oh that isn't possible, the .jar doesn't include the needed libraries in the CLASSPATH
After doing loads of work, I managed to make a batch file which will open the .jar, and I'm able to set the batch file as the default opener for an extension I want. However it isn't neat because of a simple problem - opening a batch file causes a sort of command window to open up, which is really ugly
I wonder how Processing creates the .exe file upon exporting
Processing uses launch4j apparently