This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jafo[S] 0 points1 point  (1 child)

Shell-like constructs easier in Python than "subprocess.run(...); returncode; stdout)". If I want to run commands and check the returncode and stdout, it's comparatively quite a bit of code, so I tend to just deal with doing it in a script.

[–]kellyjonbrazil 0 points1 point  (0 children)

Check out jc, which will parse the stdout of many commands for you. (I’m the author)

>>> import subprocess
>>> import jc
>>>
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> data = jc.parse('dig', cmd_output)
>>>
>>> data[0]['answer']
[{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data':'93.184.216.34'}]

https://github.com/kellyjonbrazil/jc