从 R 脚本捕获执行结果
Catch execute result from R script
我有一个从 Python 调用的 R 脚本,我想从中捕获输出。我可以写入 CMD 和 TXT,但我想在 Python 脚本中捕获输出,以便我可以使用它。
在我尝试过的 python 脚本中:
logging.debug (os.popen ('Rscript testScript.r'))
但是没用。我也试过:
output = cmd ('Rscript testScript.r')
print (output)
但它 returns None 作为输出。
在 R 中我试过:returnValue (TRUE)
但它写入了 CMD,输出仍然是 None.
如何使 R 脚本 return 成为我可以过滤以查看结果的值???
非常感谢您。
我找到了解决方案:
在 R 中,我们可以将选项放在 Try/catch
中
error = function (cond)
这反映了在 Python 中我们可以收集的输出:
print (stderr)
print (stdout)
其中stderr
是输出错误,stdout
是标准输出。
希望对遇到类似问题的人有所帮助。
我有一个从 Python 调用的 R 脚本,我想从中捕获输出。我可以写入 CMD 和 TXT,但我想在 Python 脚本中捕获输出,以便我可以使用它。
在我尝试过的 python 脚本中:
logging.debug (os.popen ('Rscript testScript.r'))
但是没用。我也试过:
output = cmd ('Rscript testScript.r')
print (output)
但它 returns None 作为输出。
在 R 中我试过:returnValue (TRUE)
但它写入了 CMD,输出仍然是 None.
如何使 R 脚本 return 成为我可以过滤以查看结果的值???
非常感谢您。
我找到了解决方案:
在 R 中,我们可以将选项放在 Try/catch
error = function (cond)
这反映了在 Python 中我们可以收集的输出:
print (stderr)
print (stdout)
其中stderr
是输出错误,stdout
是标准输出。
希望对遇到类似问题的人有所帮助。