0

So I have an exe process, but I want to be able to copy the text written to the console (shell window) into python.

I want to be able to constantly retrieve the last 3 lines from the process, and handle them in Python.

Example (ish):

process = #start the process#
preLines = []
While True:
    if process.hasExited:
        break;
    lines = #Get the last 3 lines from process#
    if lines != preLines:
        Update(lines)
        preLines = lines

The reason for this is that I have a process I want to run, but the output to be sent elsewhere, not just the default console. I have looked around, but I can't seem to find anything that works for me.

I am willing to have better suggestions as well, but would prefer something like this, as I do not want to edit the exe itself.

3
  • I think you should have a look to that other question stackoverflow.com/q/50386143/3545273. As you are speaking of exe process, I assume that the underlying OS is Windows and you should not suffer the same problem. Commented May 28, 2018 at 15:40
  • @SergeBallesta While informative, that doesn't solve the problem. The main problem is that when using popen, it pauses the thread until that process has completed. So using "start process.exe" in popen pauses the thread. Multithreading and async don't work because they do not set the variable 'process' until after the process closes. Also for some reason, I only every get a response of (b'',None) when using either process.communicate() or process.stdout.read(). Commented May 28, 2018 at 18:56
  • Please show your attempt using process.stdout.read Commented May 29, 2018 at 4:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.