Kill program being executed in Xojo Shell

Shell.Close kills the application that’s been executed in a shell on MacOS, but not in Windows.

Shell.Write(ChrB(3)) and Shell.Execute(ChrB(3)) doesn’t do it either. (Canonical On)

Anyone been able to fuck that pig? (LetterKenny reference)

Can you get the PID of the process and kill it that way?

I haven’t run across this one before and theoretically .close should have done it.

Can you force your shell to go out of scope in Xojo?

Heck, I don’t even know if this would work, but I guess you could try sending over an “exit” to the shell before doing a .close to see if that does anything.

Shell.PID doesn’t match the app.

Lol.

The normal way of closing this program when running in a command (terminal) window in Windows is Pressing Ctrl-C. (Cmd-C works in MacOS). Works fine when I run it manually, but not from a Shell in Xojo.

Lol.

Getting right on top of those bugs, I see…

It’s been ages since I’ve done Xojo shell work in Windows, but last time I remember I thought all the processes run under whatever shell object you have in Xojo. So if you tear down that object, then all children should be terminated as well. Of course this is for things not told to go into the background (e.g. & over here in Mac bash-land).

What mode of shell are you working under?

Mode 2.

Plenty of threads about this on the “other” forum, and I linked up a couple of posts a couple of bug reports that were “verified” years ago, but never fixed.
From the “other” forum:




(the methods suggested, other than TaskKill do not work, btw)

So, the shell doesn’t work as expected, that’s for sure. Likely the easiest workaround will be a
Taskkill /IM myprogram.exe /F
from another shell.

You can always try ShellMBS or WindowsProcessMBS classes in MBS Xojo Plugins if you need a different class.
(And we created those to handle some things better)

1 Like

When you start a process using the shell it does NOT start it as a dependent child process that will die when the parent dies
You can / could use a declare to ShellExecuteW to make sure this happens
Or the MBS plugins as well

There are ways to make it work

1 Like

Except that it does die on MacOS, so I was expecting the same behaviour on Windows. (Oh, fool me!)

Indeed. Using TaskKill on Windows works fine. I’ll have to see what happens on Linux when I get to that bridge.

I’d expect linux to behave more like macOS
It has to do with how the OS actually starts processes
On Windows its not the default to start them as child processes that are configured to die when the parent dies. But, if you use the Windows API to start a process its an option.
I dont think the Shell use that API configured that way to run your process - hence the weird behaviour

You could subclass shell and add a a Close method or in the Destructor of your subclass simply issue the task kill and then use your subclass everywhere and its then invisible to you there is a difference between platforms :slight_smile:

Great minds and all that…

Class KillableShell
Inherits Shell
  
  Sub Kill(App As String)

    #If TargetWindows
      Dim sh As New Shell
      sh.mode = 0 ' One-shot 
      sh.Execute("TaskKill /IM " + App + " /F") 
      System.DebugLog(sh.Result)
    #EndIf

    Me.Close 
  End Sub
End Class