在 jupyter/colab 中,如何获取 linux 命令的代码?
in jupyter/colab how can I get the code of a linux command?
我正在使用 colab,并且有一个挂载点,我可以从中解压文件,但有时它 returns 会出错。几分钟后它总是有效,所以我想重试直到它有效,但我不确定如何获取错误代码:
!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
应包含最后一次调用的退出代码。
我正在使用 colab,并且有一个挂载点,我可以从中解压文件,但有时它 returns 会出错。几分钟后它总是有效,所以我想重试直到它有效,但我不确定如何获取错误代码:
!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
应包含最后一次调用的退出代码。