I want to run a command in a python file,and then results from that command,to be inside an array so i can insert that array inside a db later.Here's my code:
import sqlite3
import subprocess
assetfinder = subprocess.Popen(["assetfinder -subs-only cysecor.rs | sort -u"], stdout=subprocess.PIPE, shell=True)
assetfinder_out = assetfinder.stdout.read().decode('utf-8')
domains = []
for item in assetfinder_out:
domains.append(assetfinder_out.strip())
print(domains)
conn.commit()
conn.close()
Here is my output:
['autodiscover.cysecor.rs\ncpanel.cysecor.rs\ncpcalendars.cysecor.rs\ncpcontacts.cysecor.rs\ncysecor.rs\nkurs.cysecor.rs\nmail.cysecor.rs\nwebdisk.cysecor.rs\nwebmail.cysecor.rs\nwww.cysecor.rs\nwww.kurs.cysecor.rs', 'autodiscover.cysecor.rs\ncpanel.cysecor.rs\ncpcalendars.cysecor.rs\ncpcontacts.cysecor.rs\ncysecor.rs\nkurs.cysecor.rs\nmail.cysecor.rs\nwebdisk.cysecor.rs\nwebmail.cysecor.rs\nwww.cysecor.rs\nwww.kurs.cysecor.rs', 'autodiscover.cysecor.rs\ncpanel.cysecor.rs\ncpcalendars.cysecor.rs\ncpcontacts.cysecor.rs\ncysecor.rs\nkurs.cysecor.rs\nmail.cysecor.rs\nwebdisk.cysecor.rs\nwebmail.cysecor.rs\nwww.cysecor.rs\nwww.kurs.cysecor.rs', 'autodiscover.cysecor.rs\ncpanel.cysecor.rs\ncpcalendars.cysecor.rs\ncpcontacts.cysecor.rs\ncysecor.rs\nkurs.cysecor.rs\nmail.cysecor.rs\nwebdisk.cysecor.rs\nwebmail.cysecor.rs\nwww.cysecor.rs\nwww.kurs.cysecor.rs', 'autodiscover.cysecor.rs\ncpanel.cysecor.rs\ncpcalendars.cysecor.rs\ncpcontacts.cysecor.rs\ncysecor.rs\nkurs.cysecor.rs\nmail.cysecor.rs\nwebdisk.cysecor.rs\nwebmail.cysecor.rs\nwww.cysecor.rs\nwww.kurs.cysecor.rs'
This cloned like 100 times.I want to get every item not all items in 1 item,and then that one item cloned 100 times.Any fix??
1 Answer 1
assetfinder_out is a str object. You iterate over it and for every char append the whole string to domains list.
As far as I can see the assets are delimited by new line \n. So just split the string.
import subprocess
assetfinder = subprocess.Popen(["assetfinder -subs-only cysecor.rs | sort -u"], stdout=subprocess.PIPE, shell=True)
assetfinder_out = assetfinder.stdout.read().decode('utf-8')
domains = assetfinder_out.splitlines()
answered Dec 17, 2021 at 8:01
buran
14.4k13 gold badges45 silver badges76 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
MasterX
Yea it works fine,didnt know that assetfinder_out is a str object.However thanks mate
lang-py
domains = assetfinder_out.strip().split()...?