jaredrummler / KtSh

Execute shell commands on Android or the JVM
http://jaredrummler.github.io/ktsh/
Apache License 2.0
711 stars 151 forks source link

Subprocess spawned from inside shell does not stop when shell.interrupt() or shell.shutdown() is called. #27

Open cryptrr opened 3 days ago

cryptrr commented 3 days ago

I am running a python script using shell.run()

But even after interrupt() or even shutdown(), the subprocess spawned inside the python script still keeps running.

val result = shell.run(command)

Timber.d("Exit Code ${result.exitCode}") //Correctly receives non zero exit code.

Is this an issue with signal forwarding or am I doing anything wrong?

init {
          main.viewModelScope.launch {
              main.eventFlow.collect{
                  when(it){
                      is ViewModelEvent.CancelProcess -> {
                          CoroutineScope(Dispatchers.IO).launch {
                              //Event is fired
                              shell.interrupt()
                       }
                     }
                     else -> {}
                }
           }
      }
 }

shell = Shell("/path/to/sh")

fun runCommandForShareWithEnv(command: String){
     CoroutineScope(Dispatchers.IO).launch{
         val result = shell.run(command)
         Timber.d("Exit Code ${result.exitCode}") //Correctly receives non zero exit code.
     }
}
cryptrr commented 3 days ago

This is for a FOSS project. https://github.com/cryptrr/AutoPie