在 R 中捕获 At 命令的 ID
Capture ID of At Command in R
问题:我想捕获at命令作业的id
这是执行at命令的正常代码
> system(command="echo touch my_path/test_file.in | at 05:26 AM")
这是输出
job 984 at 2015-12-11 05:26
因为我想捕获 at 命令的 id,所以我添加了 system() 函数的 "intern" 参数并将 id 保存到变量
> id<-system(command="echo touch my_path/test_file.in | at 05:26 AM", intern=TRUE)
仍然没有捕获输出所以我尝试了 system2() 函数
> id<-system2(command="echo touch my_path/test_file.in | at 05:26 AM", stdout=TRUE, stderr=TRUE)
还是行不通。有人可以帮我解决这个问题吗?
system2()
引用命令所以你可能想使用像
id <- system2(
"sh",
c("-c","echo touch my_path/test_file.in | at 05:26 AM"),
stdout=TRUE, stderr=TRUE
)
或者,您可以坚持 system()
并重新定向 stderr
:
id <- system("echo touch my_path/test_file.in | at 05:16 AM 2>&1", int=T)
问题:我想捕获at命令作业的id
这是执行at命令的正常代码
> system(command="echo touch my_path/test_file.in | at 05:26 AM")
这是输出
job 984 at 2015-12-11 05:26
因为我想捕获 at 命令的 id,所以我添加了 system() 函数的 "intern" 参数并将 id 保存到变量
> id<-system(command="echo touch my_path/test_file.in | at 05:26 AM", intern=TRUE)
仍然没有捕获输出所以我尝试了 system2() 函数
> id<-system2(command="echo touch my_path/test_file.in | at 05:26 AM", stdout=TRUE, stderr=TRUE)
还是行不通。有人可以帮我解决这个问题吗?
system2()
引用命令所以你可能想使用像
id <- system2(
"sh",
c("-c","echo touch my_path/test_file.in | at 05:26 AM"),
stdout=TRUE, stderr=TRUE
)
或者,您可以坚持 system()
并重新定向 stderr
:
id <- system("echo touch my_path/test_file.in | at 05:16 AM 2>&1", int=T)