簡體   English   中英

如何在shell腳本中運行R腳本的退出狀態

[英]How to get exit status of R script run in shell script

假設我正在從這個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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM