Я пытаюсь напечатать любые строки в текстовом файле со словами Сеть или Диагностика .Тем не менее, вывод выводит все строки в файле.Для этого скрипта мне нужно просто напечатать строки с вышеуказанными словами.import os
os.system("NET START > c:\\temp\\mypythonfiles\\currservices.txt")
path1="c:\\temp\\mypythonfiles\\currservices.txt"
list1=[]
substr1="Network"
substr2="Diagnostic"
tstring=substr1+substr2
stop=open("c:\\temp\\mypythonfiles\\currservices.txt","rt")
with open(path1,"rt") as file :
for line in file:
list1.append(line)
if line.find(tstring):
for line in list1:
print("Service found:",line, sep=" ")
stop.close()
Вот вывод:
Service found: The command completed successfully.
Service found: These Windows services are started:
Service found:
Service found: Application Information
Service found: aswbIDSAgent
Service found: Avast Antivirus
Service found: Background Tasks Infrastructure Service
Service found: Base Filtering Engine
Service found: CNG Key Isolation
Service found: COM+ Event System
Service found: Connected Devices Platform Service
Service found: Connected Devices Platform User Service_2f2f13e
Service found: Connected User Experiences and Telemetry
Service found: Contact Data_2f2f13e
Service found: CoreMessaging
Service found: Credential Manager
Service found: Cryptographic Services
Service found: Data Sharing Service
Service found: Data Usage
Service found: DCOM Server Process Launcher
Service found: Delivery Optimization
Service found: Device Association Service
Service found: DHCP Client
Service found: Diagnostic Policy Service
Service found: Diagnostic Service Host
Service found: Distributed Link Tracking Client
Service found: DNS Client
Service found: Geolocation Service
Service found: Human Interface Device Service
Service found: IKE and AuthIP IPsec Keying Modules
....rest of NET START LIST
Я пробовал довольно много вещей, чтобы заставить его работать, но вывод почти всегда как выше.Любая помощь будет отличной.