安排一个显示 popup/message 框的 R 脚本,以防 Windows 出错
Scheduling an an R script that shows a popup/message box in case of an error on Windows
我的目标是每 5 分钟检查一次网站的 http 状态,并在它不是 200 时发出警告消息。为简单起见,我想根据给出的代码讨论我的问题下面。
library(httr)
a <- status_code(GET("http://httpbin.org/status/404"))
if (a == 404) system('CMD /C "ECHO Client error: (404) Not Found && PAUSE"',
invisible=FALSE, wait=FALSE)
在
上找到的以 system
开头的最后一位
https://heuristically.wordpress.com/2013/04/19/popup-notification-from-r-on-windows/
和
Show a popup/message box from a Windows batch file
上面几行的结果是
这是从 C:\windows\SYSTEM32\CMD.exe 弹出的消息框,上面写着:
客户端错误:(404) 未找到
按任意键继续...
是否可以在此消息中添加 Sys.time()?
我使用 taskscheduleR 安排了上面的脚本。要获得帮助,请参阅:
library(taskscheduleR)
myscript <- "the address of your r script"
taskscheduler_create(taskname = "myfancyscript_5min", rscript = myscript,
schedule = "MINUTE", starttime = "11:20", modifier = 5)
在这种情况下,我得到的消息框如下所示。请注意,这次它没有消息。
当我 运行 使用任务调度程序的脚本时,如何获取写入的消息?
您只需编辑代码的第一部分。正如评论中所建议的,我们将使用通知程序:
https://github.com/gaborcsardi/notifier
如果您在安装通知程序时遇到问题,我只能通过以下命令安装它。
devtools::install_version("notifier")
将第一位替换为以下内容:
library(httr)
library(notifier)
a <- status_code(GET("http://httpbin.org/status/404"))
if (a == 404) notify(
title = "404",
msg = c("Client error: (404) Not Found")
)
我的目标是每 5 分钟检查一次网站的 http 状态,并在它不是 200 时发出警告消息。为简单起见,我想根据给出的代码讨论我的问题下面。
library(httr)
a <- status_code(GET("http://httpbin.org/status/404"))
if (a == 404) system('CMD /C "ECHO Client error: (404) Not Found && PAUSE"',
invisible=FALSE, wait=FALSE)
在
上找到的以system
开头的最后一位
https://heuristically.wordpress.com/2013/04/19/popup-notification-from-r-on-windows/
和
Show a popup/message box from a Windows batch file
上面几行的结果是
这是从 C:\windows\SYSTEM32\CMD.exe 弹出的消息框,上面写着:
客户端错误:(404) 未找到
按任意键继续...
是否可以在此消息中添加 Sys.time()?
我使用 taskscheduleR 安排了上面的脚本。要获得帮助,请参阅:
library(taskscheduleR)
myscript <- "the address of your r script"
taskscheduler_create(taskname = "myfancyscript_5min", rscript = myscript,
schedule = "MINUTE", starttime = "11:20", modifier = 5)
在这种情况下,我得到的消息框如下所示。请注意,这次它没有消息。
当我 运行 使用任务调度程序的脚本时,如何获取写入的消息?
您只需编辑代码的第一部分。正如评论中所建议的,我们将使用通知程序:
https://github.com/gaborcsardi/notifier
如果您在安装通知程序时遇到问题,我只能通过以下命令安装它。
devtools::install_version("notifier")
将第一位替换为以下内容:
library(httr)
library(notifier)
a <- status_code(GET("http://httpbin.org/status/404"))
if (a == 404) notify(
title = "404",
msg = c("Client error: (404) Not Found")
)