关闭从 R 启动的外部应用程序 [英] Close external application launched from R

查看:34
本文介绍了关闭从 R 启动的外部应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以关闭从 R 中启动的应用程序?

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

假设我打开了一个 CSV 文件 my_file.csv 及其关联的应用程序 通过 shell.exec 函数.然后我想关闭这个应用程序.

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.

推荐答案

由于 R 无法控制其他程序,因此您无法可靠地直接关闭在没有 R 的情况下打开的文件.您甚至不知道要关闭哪个程序.例如.在一台电脑上用记事本打开csv文件,在另一台电脑上用Excel打开.

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.

如果您知道该程序,您可以使用 system2() 或类似的命令来执行一个命令来杀死另一个程序.例如.如果要关闭 Excel,请执行 system2("taskkill", args = "/im excel.exe").请注意,这将关闭程序/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.

这篇关于关闭从 R 启动的外部应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆