command_runner icon indicating copy to clipboard operation
command_runner copied to clipboard

How to get program stdout input when running as elevated

Open joeavanzato opened this issue 4 years ago • 2 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

joeavanzato avatar Dec 03 '21 17:12 joeavanzato

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 avatar Dec 04 '21 10:12 deajan

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.

joeavanzato avatar Dec 04 '21 20:12 joeavanzato