-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeispiel_subprocess.py
More file actions
36 lines (32 loc) · 863 Bytes
/
Beispiel_subprocess.py
File metadata and controls
36 lines (32 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
##############################################
#
# Name: Beispiel_subprocess.py
#
# Author: Peter Christen
#
# Version: 1.0
#
# Date: 01.10.2016 1.0
#
# Purpose: Ausführen eines Kommandos mit subprocess
#
##############################################
import subprocess
kommando = ['ls', '-l', 'Beispiel_subprocess.py', 'Beispiel.sonstwas.py']
ssh = subprocess.Popen(kommando,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
#Ausgabe standard output
result = ssh.stdout.readlines()
for r in result:
print(r[:-1].decode('utf8'))
#Ausgabe standard error output
error = ssh.stderr.readlines()
if error:
print('\033[0;31m') #rot
for e in error:
print(e[:-1].decode('utf8'))
print('\033[0;30m') #schwarz