let's say i have an executable file stored in c:\my directory\my file.exe
that i would like to initiate near the beginning of my R script, and then terminate near the end of my R script. what are some clean ways do this on a windows platform?
i am aware of R commands like shell
and shell.exec
, but it's not clear to me that these will allow a clean capture of the process id to then use something like the pskill function. it's also not clear if it makes more sense to run this executable through some sort of pipe conection - or how that pipe would work. this particular executable should be included in my windows PATH
as a system variable, so it's conceivable that the system
function might be of value here as well.
additional clarification: capturing the process id might be important, because (at least for me) this will be used on a database server's executable -- if multiple database servers are currently running on the same machine, the process shouldn't kill all of them - just the one initialized at the start of the R script.
for extra credit: let's say c:\my directory\my file.exe
should be called by actually executing another file - c:\my directory\another file.bat
- but it's my file.exe
that needs to be killed at the end of the R script.
You could use
system
function:edit: This worked in my computer with Windows 7 (tested with killing skype.exe).
drawing on the other two answers received, this technique seems like a reasonable way to accomplish the stated goal..
In the past, I used psKill. It is really powerful and maybe dangerous. You kill multi-procees even ina remote computer. I think you konw we must be extremely careful when we want to kill brutally process.
Then you use somthing like this
For example to kill all chrome instances, you do this
EDIT
Assuming you have multi process with the same name. You can use
pslist
to list all process with this name. Find the id of the process you want to kill according to its elapsed time, then call pskill by id.For example here I want to kill , the last launched chrome process