Форум сайта python.su
88
mbele-mbele
Как бы их устранить.
for line in proc_list.stdout: print line.rstrip()
Офлайн
0
Shaman
СПАСИБО!
Офлайн
88
Ого! Пожалуйста! )
Офлайн
.
Отредактировано J.R. (Фев. 27, 2016 16:50:03)
Офлайн
88
Всё же переводить строки лучше поручить системе.
Офлайн
0
J.R.
Да тоже работает спасибо, занесу в копилку.
))
Офлайн
0
ПОзвольте еще маленький вопрос
# -*- coding: utf-8 -*- import subprocess import os os.system("cls") proc_list = subprocess.Popen('tasklist', shell=True, stdout=subprocess.PIPE) lines = [] for line in proc_list.stdout: if 'PID' in line: utext = unicode(line.rstrip(), 'cp1251', 'replace') print utext.rstrip() if '========' in line: print line.rstrip() if 'firefox.exe' in line: lines.append(line) print line.rstrip() exit()
C:\Python27\python.exe C:/001/test12.py
€¬п ®Ўа § PID €¬п бҐббЁЁ ь бҐ б Џ ¬пвм
========================= ======== ================ =========== ============
firefox.exe 5664 Console 17 428я232 ЉЃ
Process finished with exit code 0
Отредактировано mbele-mbele (Сен. 1, 2015 22:42:08)
Офлайн
88
# -*- coding: utf-8 -*- import sys reload(sys) import locale sys.setdefaultencoding(locale.getpreferredencoding()) import subprocess import os os.system("cls") proc_list = subprocess.Popen('tasklist', shell=True, stdout=subprocess.PIPE) lines = [] for line in proc_list.stdout: if 'PID' in line: utext = unicode(line.rstrip(), 'cp1251', 'replace') print utext.rstrip() if '========' in line: print line.rstrip() if 'firefox.exe' in line: lines.append(line) print line.rstrip() exit()
Отредактировано Shaman (Сен. 1, 2015 22:55:55)
Офлайн
0
Shaman
Странно , но у меня
win8.1x64
Python 2.7
но даже с Вашими вставками “крючки” не пропали
C:\Python27\python.exe C:/001/test12.py
€¬п ®Ўа § PID €¬п бҐббЁЁ ь бҐ б Џ ¬пвм
========================= ======== ================ =========== ============
firefox.exe 5664 Console 17 517я148 ЉЃ
Process finished with exit code 0
Отредактировано mbele-mbele (Сен. 1, 2015 23:28:10)
Офлайн
0
“Сверх” задача у меня - совместить вывод двух программ.
Вся программа выглядит так
# -*- coding: utf-8 -*- import subprocess import re import os # -*- coding: utf-8 -*- import sys reload(sys) import locale sys.setdefaultencoding(locale.getpreferredencoding()) os.system("cls") pattern=re.compile(r"\d{2,}") proc_list = subprocess.Popen('tasklist', shell=True, stdout=subprocess.PIPE) nets_list = subprocess.Popen('netstat -ano', shell=True, stdout=subprocess.PIPE) lines = [] for line in proc_list.stdout: if 'PID' in line: utext = unicode(line.rstrip(), 'cp1251', 'replace') print utext.rstrip() if '========' in line: print line.rstrip() if 'firefox.exe' in line: lines.append(line) print line.rstrip() for id in lines: did=pattern.search(id).group(0) for netstr in nets_list.stdout: if did in netstr: print ("\t\t%s"%netstr.rstrip()) exit()
C:\Python27\python.exe C:/001/test11.py
€¬п ®Ўа § PID €¬п бҐббЁЁ ь бҐ б Џ ¬пвм
========================= ======== ================ =========== ============
firefox.exe 5664 Console 17 520я212 ЉЃ
TCP 127.0.0.1:1701 127.0.0.1:1702 ESTABLISHED 5664
TCP 127.0.0.1:1702 127.0.0.1:1701 ESTABLISHED 5664
TCP 192.168.0.102:4335 109.74.193.139:80 ESTABLISHED 5664
TCP 192.168.0.102:4336 109.74.193.139:80 ESTABLISHED 5664
TCP 192.168.0.102:4337 173.194.113.201:80 ESTABLISHED 5664
TCP 192.168.0.102:4342 50.31.164.173:80 ESTABLISHED 5664
Process finished with exit code 0
Отредактировано mbele-mbele (Сен. 1, 2015 23:34:39)
Офлайн