简体   繁体   中英

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

I'm using colab and there is a mount point that I untar a file from but sometimes it returns an error. After a few minutes it always works so I'd like to retry until it works but I am not sure how to get the error code:

!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

Ideally I want to get an error and process it like:

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

I would try following:

from IPython import get_ipython

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

Variable exit_code should contain exit code of the last call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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