gpt4 book ai didi

r - 如何获取在shell脚本中运行的R脚本的退出状态

转载 作者:行者123 更新时间:2023-11-29 09:15:27 28 4
gpt4 key购买 nike

假设我从这个 shell 脚本中运行一个 Rscript

#!/bin/bash
RES=$(./abc.R 100)
r_status=echo $?

abc.R 中有一些代码停止了它的执行

#!/usr/bin/env Rscript
...
...
if(nrow(status) == 0)
{ stop("The list id is not present in requests table. Please check.") } else if (status != 'COMPLETED')
{ stop("The list is not in COMPLETED state. Please check.")}
...
...

我无法在我的 shell 脚本中捕获 abc.R 的退出状态。它停止 R 的执行,甚至从 shell 脚本退出到提示符。

有什么方法可以捕获 R 的退出状态。

最佳答案

只需运行您想要的脚本。确保它在完成运行时返回正确的退出状态。这应该有效:

#!/bin/bash
./abc.R 100
if [ $? == 0 ]; then
echo "Your script exited with exit status 0"
exit 0

在这里查看更多: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html

关于r - 如何获取在shell脚本中运行的R脚本的退出状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41464438/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com