#๐Ÿ”’ Possible to catch cls with subprocess.Popen?

14 messages ยท Page 1 of 1 (latest)

wind jacinth
#

i am currently hooking into another running exe with subprocess

import subprocess

cmd = "process.exe"
proc = subprocess.Popen(cmd, shell=True, bufsize=256, stdout=subprocess.PIPE)

def subprocess_readlines(out):
    while True:
        line = out.readline()
        if not line:
            return
        yield line

for line in subprocess_readlines(proc.stdout):
    print(">>>", line.rstrip().decode("utf-8"))

the original program itself is written in Go, and it clears the window using cls

    clearFuncMap["windows"] = func() {
        cmd := exec.Command("cmd", "/c", "cls")
        cmd.Stdout = os.Stdout
        cmd.Run()
    }

How do I capture this cls command and clear my own output accordingly? My goal here is to redirect all output to be sent via a Discord channel, but restructing my the entire Go code to run with discord will be too time consuming.

winged acornBOT
#

@wind jacinth

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vital crane
#

What happens if you use subprocess.run("cls", check=True)?

wind jacinth
#

this does clear the console window

import subprocess
subprocess.run("cls", check=True, shell=True)
#

but i still require a way to check if a cls is called from the original program

vital crane
#

Oh I see what you're saying

wind jacinth
#

Yep haha

#

I know this deviates a little from Python, but if there is a possible way to capture a clear screen with minimal changes to the Go code, I am open for suggestions

vital crane
#

cls doesn't do anything if attached to a pipe

#

You need to attach it to a TTY

wind jacinth
#

but this does mean if i was to use tty, i wld require a unix like environment instead, due to termios. the binary i am running is however an exe for Windows. Is there any tty library equivalent in an Windows env? I dont seem to be able to find anything

winged acornBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.