Close external application launched from R

馋奶兔 提交于 2019-12-31 05:03:25

问题


Is it possible to close an application that was launched from within R?

Assume that I have opened a CSV file my_file.csv with its associated application via the shell.exec function. I then want to close this application.


回答1:


Since R has no control over other programs you cannot directly close files opended without R reliably. You do not even know which program to close. E.g. one one computer a csv file may be opened with notepad, on another computer it may be opened with Excel.

If you know the program you can use system2() or similar commands to execute a command to kill the other program. E.g. if you want to close Excel execute system2("taskkill", args = "/im excel.exe"). Note that this will close all open instances of the program/Excel, not jut a specific one.



来源:https://stackoverflow.com/questions/55849698/close-external-application-launched-from-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!