Piers Rowan via luv-main <luv-main@luv.asn.au> writes:

> I am playing with Python so I have an application to start and stop 
> services as a GUI.
>
> I would prefer not to type sudo python /path/to/script.py as I might as 
> well just use the command line.
>
> This is just a useful toy to me to help learn a bit about Python. I hope 
> to add to it down the track.
>
> I tried to use pkexec:
>
> result = subprocess.run(['pkexec', 'systemctl', 'list-unit-files', 
> '--type=service', '--no-pager', '--plain'], capture_output=True, 
> text=True, check=True)
>
> ...but it just looped and never ran the command.
>
> Any ideas brains trust?
I think I would try, at least initially, with capture_output=False (the
default). You might find that sudo/pkexec is trying to get you to
authenticate, and this is failing because the output is being
redirected. Particularly capture_output captures both stdout and stderr.

If that works, then a solution that captures stdout only and not stderr
might work better.

sshuttle does something similar to start its firewall process, and then
it talks to the firewall process via stdin/stdout. But it sort of grown
organically and begging to be refactored into something that could be
easier to understand.
https://github.com/sshuttle/sshuttle/blob/master/sshuttle/client.py#L209-L337

sshutle also uses subprocess.Popen, hopefully for you application where
you only need stdout subprocess.run should be sufficient.
-- 
Brian May @ Linux Penguins
_______________________________________________
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au
  • Systemd - Python Piers Rowan via luv-main
    • Re: Systemd - Python Brian May via luv-main

Reply via email to