B4J Library jShell library


Staff member
Licensed User
The jShell library allows you to start other programs. It is based on Apache Commons Exec project: http://commons.apache.org/proper/commons-exec/index.html

The programs are always started asynchronously. ProcessComplete event is raised when the process completes.

The following code will run the Java program we previously created:

Sub AppStart (Args() As String)
   Dim shl As Shell
   shl.Initialize("shl", "java", _
     Array As String("-cp", "curl.jar", "b4j.example.main", "http://www.basic4ppc.com"))
   shl.WorkingDirectory = "C:\Users\H\Documents\B4J\Curl\Objects"
   shl.Run(10000) 'set a timeout of 10 seconds
   StartMessageLoop 'need to call this as this is a console app.
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   If Success AND ExitCode = 0 Then
     Log("Error: " & StdErr)
   End If
End Sub
The Shell library can be used in a UI app in the same way.

Installation instructions:
- Download the attached zip file.
- Unzip it and copy jShell.xml and jShell.jar to the additional libraries folder or to the internal libraries folder.

V1.30 is released - Includes a method to start a process and wait for it to complete. You should normally not use this method in a UI application as it will block the UI thread.


Last edited:


Well-Known Member
Licensed User
The example seems to use a Windows folder as the WorkingDirectory.

I guess it can also be used within Linux to launch Linux commands ?

Can it also be used to launch a Linux command which pipes out its output (to be read in the event handler) ?


Well-Known Member
Licensed User
I cannot understand how to run .exe and exit my app. My app closes the starting app2 also when exiting.
Last edited:


Licensed User
The shell works for me only if I change the jar to exe (with launch4j)
shl.Initialize("shl", "server_report.exe", Array As String(name))
otherwise there is an error saying that this is not a windows executable. The application is a UI one.
Last edited:


Licensed User
Thank you. The first option does not work in non Ui .
The shell works with jar like this:
 shl.Initialize("shl", "java.exe" , Array As String("-jar", "Server_report.jar",name))


Active Member
Licensed User
StdOut and StdErr strings hold the process output.
Hi , is there a way to find out if "example.exe"(dos cmd) has finished downloading a file with Jshell if the "example.exe" does not close if download is complete ?
or i just have to track the bytes written and compare if the file size has changed in the last second