0

问题:我想捕获 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)


还是行不通。有人可以帮我弄这个吗?

4

1 回答 1

1

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)
于 2015-12-11T03:54:36.437 回答