Created
April 17, 2013 14:47
-
-
Save maltzsama/5404900 to your computer and use it in GitHub Desktop.
Python subprocess.check_call([''])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| >>>import subprocess | |
| >>>subprocess.check_call(['false']) | |
| #Todos sabemos que não existe um comando false. Logo este comando retornará um erro na tela. Da seguinte forma: | |
| #A saída do da execução desse comando será | |
| Traceback (most recent call last): | |
| File "subprocess_check_call.py", line 11, in <module> | |
| subprocess.check_call(['false']) | |
| File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2. | |
| 7/subprocess.py", line 511, in check_call | |
| raise CalledProcessError(retcode, cmd) | |
| subprocess.CalledProcessError: Command '['false']' returned non-zero e | |
| xit status 1 | |
| #Se nós tivessemos usado simplesmente o call(), nosso unico retorno seria o número 1 ao fim da execução do comando. | |
| #Ainda é possível fazer a captura de erros de outra forma. Mas colocarei isso em outro post. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment