B4J Question NullPointerException when killing a process

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I launch an external process (php server) using jShell and after a while I want to kill this process (demo app):

B4X:
Sub AppStart (Args() As String)
    shl.Initialize("shl", "c:/php/php.exe", Array As String ("-S", "0.0.0.0:8000"))
    
    tmr.Initialize("tmr", 10000)
    tmr.Enabled = True
    
    StartMessageLoop
End Sub

Sub tmr_Tick
    shl.KillProcess
End Sub

When I try to kill the process I get a NullPointerException:

at anywheresoftware.b4j.objects.Shell.KillProcess(Shell.java:146)
 

wl

Well-Known Member
Licensed User
Longtime User
I extended the code but receive the same error.

Note that it is a console application.

B4X:
Sub AppStart (Args() As String)
    shl.Initialize("shl", "c:/php/php.exe", Array As String ("-S", "0.0.0.0:8000"))  
    shl.Run(-1)
    tmr.Initialize("tmr", 10000)
    tmr.Enabled = True
   
    StartMessageLoop
End Sub


Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log (Success)  
End Sub

Sub tmr_Tick
    shl.KillProcess
End Sub

 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Are you sure the process has actually been started? Does it show up in task manager ?
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Thanks all. My mistake ... I ran the shell inside a server application that was also listening on port 8000 (the same port I asked the php server to listen to). I did not include this code as it seemed not relevant :-( Sorry

so in fact the PHP server was never started (though I did not notice this and I thought it was) ad so killing it resulted in the error.

Then in fact in a next step there was again the nullpointer exception: but in this case it was indeed cause the second time the timer ticked (as Erel indicated)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…