Closing other program/service from my code

I know we can start another app from the Go code using https://golang.org/pkg/os/exec/#example_Cmd_Run

Is there a way to close/shut another app/process from my code, for example I want want to close MS excel if it is running.

Maybe the following approach

  • open excel or any other program from cli. Note for some og the you need to check if they are in path, otherwise in won’t work.
  • search the pid of process and invoke the kill(linux) or Taskkill for windows with the pid in linux case or the process name in case of Windows. Note that for Linux you can send the CTRL-C/SIGINT and the program will terminate

https://en.wikipedia.org/wiki/Signal_(IPC)#SIGINT

Also check if that application has some cli options and switches. In particular for excel, there are a few.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.