繁体   English   中英

在 jupyter/colab 如何获取 linux 命令的代码?

[英]in jupyter/colab how can I get the code of a linux command?

我正在使用 colab,并且有一个挂载点可以从中解压文件,但有时它会返回错误。 几分钟后它总是有效,所以我想重试直到它有效,但我不确定如何获取错误代码:

!tar -xzvf $filename

Not downloading data
tar (child): ./companyJSON/filePath.tar.gz: Cannot open: Input/output error
tar (child): Error is not recoverable: exiting now

gzip: stdin: unexpected end of file
tar: Child returned status 2
tar: Error is not recoverable: exiting now

理想情况下,我想得到一个错误并像这样处理它:

def untarrerFunc(filename):
   !tar -xzvf $filename
   if ErrorCode != 0:
       untarrerFunc(filename)

我会尝试以下:

from IPython import get_ipython

exit_code = get_ipython().__dict__['user_ns']['_exit_code']

变量exit_code应包含上次调用的退出代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM