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

Using elevate disables all print outputs in compiled console window

Zenahr opened this issue · comments

I'm writing this piece of software currently: https://github.com/Zenahr/ALACS
and am using this lib to allow it to work properly.

It does solve the problem I had (monitoring keyboard input while having the program window being not focused), however after implementing elevate the console window remains blank.

Why is that? Am I using the API wrong? Is there an option I don't know of that I could pass to elevate()?

This is my main code for reference:

import pynput
from pynput import keyboard
import lib
from lib import click_random_legend, click_main_legends
import json
from command_runner.elevate import elevate

ACTIVATION_BUTTON = json.load(open('./config.json'))['key']

def main():
    def on_press(key):
                if key == keyboard.Key[ACTIVATION_BUTTON]:
                    if not json.load(open('./config.json'))['select_random_legend']:
                        click_main_legends()
                    else:
                        click_random_legend()

    def on_release(key):
        pass

    print('BOOTING UP ALACS ...')
    print('BOOTED UP ALACS')
    print('MAKE SURE TO CLOSE THIS WINDOW AFTER CLOSING APEX')
    print('TO CHANGE THE ACTIVATION KEY READ THE INSTRUCTIONS FOUND IN instructions.txt')
    print('ACTIVATION KEY IS SET TO:', '>>> ', ACTIVATION_BUTTON, ' <<<')
    print('LISTENING FOR ACTIVATION KEY ...')

    with keyboard.Listener(
            on_press=on_press,
            on_release=on_release) as listener:
        listener.join()

if __name__ == '__main__':
    elevate(main)

Hello,

This comes from the fact that the windows API that reloads the executable with UAC privileges (ShellExecuteEx) does not allow to capture console output.
Unfortunately there's not much I can do about it.
In order to have output, such programs are supposed to output data whether via a GUI or via a log file.

Thanks a lot! I know what to do then. Thanks for the explanation.