I am using the javapackager tool in the JDK to package a java command-line application into a Windows executable file.
Unfortunately, when I execute the generated .exe file from a command prompt, the stdout from the packaged Java application is not re-directed back to the command prompt. This prevents a user from viewing the output from the application.
Is there a way to configure the javapackager tool so that stdout from the Java application is re-directed to the command prompt where it was launched?
Any help would be appreciated!
Had a similar problem. In my application, the main function runs a JavaFX GUI if no command line options are supplied and runs the CLI with arguments. Without stdout, there is no way for the user to know if the application executed properly when running the command line version.
The .exe runs the equivalent of javaw.exe so stdout is suppressed. You can pipe stdout to a file at the command line or you can run "MyApp.exe | MORE" and it will print stdout back to the console.
For my final solution, I added a drop-in "package\windows\MyApp-post-image.wsf" to create a batch script in the installation directory.
<?xml version="1.0" ?>
<package>
<job id="postImage">
<script language="JScript">
<![CDATA[
var fso, f;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.CreateTextFile("MyApp/MyApp.bat", true);
f.WriteLine("@echo off");
f.WriteLine("MyApp.exe %* | MORE");
f.Close();
]]>
</script>
</job>
</package>
The batch script passes any command line parameters to the EXE and pipes the output back to the console. This method would not work if your command line application requires user input during execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With