B4J Question jShell error

yo3ggx

Active Member
Licensed User
Longtime User
Hello.

I try to run an exe file using jShell.
The following simple code is used:
B4X:
Dim sh1 as Shell
sh1.Initialize("sh1","myapp.exe",Array As String("-d","1","-p","5174"))
sh1.WorkingDirectory = "C:\MyApp"
sh1.RunWithOutputEvents(-1)
then I have
B4X:
Sub sh1_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
    Log("Error: " & StdErr)
End Sub

When executed, I get the following error:
B4X:
Error: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "myapp.exe" (in directory "C:\MyApp"): CreateProcess error=2, The system cannot find the file specified)

If from Windows command prompt I enter the command:
B4X:
C:\MyApp\myapp.exe -d 1 -p 5174
the application is executed.

What I'm doing wrong?

Thank you.
 

yo3ggx

Active Member
Licensed User
Longtime User
You need to pass the full path in the Initialize line. It is relative to the app folder, not the "WorkingDirectory".
This was my mistake. I try with the full path (like for WorkingDirectory), not relative path.

Thank you.
 
Last edited:
Upvote 0
Top