End shell

How do I close a shell process? shell.close doesn’t do anything. I tried to send Ctrl+C to the shell as well with no luck.

thanks

How about Exit

See https://forum.xojo.com/6243-force-quit-a-shell-windows

How do you suggest I use the exit function?

Thanks

[quote=97151:@Adam Meyer]How do you suggest I use the exit function?
[/quote]

The exit function cannot work with a synchronous shell, because the app is frozen while the shell has not ended. Even a timer wil not work.

The only simple solution is to use shell.mode = 1 which lets you app continue. If you want to kill the shell process (which can be seen by ps aux in the Terminal), you can then use shell.close.

If you need to obtain a result from the asynchronous shell, insert it in the project as a class, and add the DataAvailable handler. See http://documentation.xojo.com/index.php/Shell for more.

The shell mode is equal to 1. But it still doesn’t close with shell.close. The app hangs until I end the process in the task manager. Then the app continues.

In mode 0 shell.timeout does stop the shell when instructed.

See http://documentation.xojo.com/index.php/Shell.TimeOut

Same result. Doesn’t close. How do I close a shell with timeout? That’s a property, not a method.

You set the timeout before starting shell.execute, so you are sure your app will not be held longer than the timeout.

But… Have you checked https://forum.xojo.com/6243-force-quit-a-shell-windows ?

I see several methods posted there that could satisfy your need, including a couple to terminate the process the same way you do it by taskkill…

For windows you can also do this:

  // More info: http://msdn.microsoft.com/en-us/library/ateytk4a%28v=vs.84%29.aspx
  
  Dim oShell, oRes As OLEObject
  Dim n As Integer
  
  oShell = NEW OLEObject ("WScript.Shell")
  oRes = oShell.exec("calc.exe")
  
  
  n = MsgBox("Close calc?", 32)
  If n = 1 Then
    //user pressed OK
    oRes.Terminate
    oShell = Nil
  End If
  

More info about using this shell Object see:

  1. https://forum.xojo.com/19042-windows-shell-very-slow-in-calling-dataavailable-event/p1#p159945
  2. http://msdn.microsoft.com/en-us/library/ateytk4a(v=vs.84).aspx