>>>import subprocess
>>>subprocess.call('ls | wc -l', shell=True)
3
0 --> finish successfully
>>>subprocess.call(['touch', 'plik'])
0
>>>subprocess.call(['ls', '-ltr'])
razem 8
-rw-r--r-- 1 root root 28 lip 2 14:28 plik.tajemny
-rwxr-xr-x 1 root root 680 lip 3 10:24 test.py
-rw-r--r-- 1 root root 0 lip 3 10:34 plik
0
error example:
>>>subprocess.call('ls | wc -lasd', shell=True)
wc: błędna opcja -- 'a' -->; error message
Napisz 'wc --help' dla uzyskania informacji.
ls: błąd zapisu: Przerwany potok
1 -->; error code
the same error code OS use when we try to execute wrong command
simple example from the OS
root@ubu:~# cat /etc/passwd123
cat: /etc/passwd123: there is no file
root@ubu:~# echo $?
1
Brak komentarzy:
Prześlij komentarz