netinvent / command_runner

Substitute for subprocess that handles all hassle that comes from different platform and python versions, and allows live stdout and stderr capture for background job/interactive GUI programming ;)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get program stdout input when running as elevated

joeavanzato opened this issue · comments

Hello team,

Great module - but I am having a slight problem - when I execute my main() so that the entire script runs elevated, how can I maintain the stdout that was appearing previously?

Thanks,
Joe Avanzato

Unfortunately, there's no good way to get stdout/stderr pipes from Windows ShellExecuteEx function needed for process elevation inside command_runner, so you basically won't get any console output.

As a workaround, you might log from your main into a file, which you can read later, or even read that logfile with a thread to have on-the-fly output.

There's no other good python solution to this AFAIK.
Some excellent lecture about the Windows UAC API https://www.codeproject.com/Articles/19165/Vista-UAC-The-Definitive-Guide

deajan,

Thank you for the excellent feedback! I did do a significant amount of research on this yesterday and realized that after posting :(

One thing I would ask though - how can I get the elevate module to spawn a new cmd terminal in Windows so that at least the output is visible on-screen? The standard subprocess.popen arguments I tried to pass to elevate() did not seem to function as expected.