0

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
  • domains = assetfinder_out.strip().split()…? Commented Dec 17, 2021 at 8:00

1 Answer 1

4

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Yea it works fine,didnt know that assetfinder_out is a str object.However thanks mate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.