tkterminal icon indicating copy to clipboard operation
tkterminal copied to clipboard

Tkterminal interprets output without newline as part of next command

Open ShayanShahsiah opened this issue 1 year ago • 1 comments

Steps to Reproduce:

  1. Run printf Hello in a tkterminal instance (I'm using shell=True)
  2. The output is: Hellotkterminal$
  3. Now press Return

Expected Behavior: The output should be empty because no command was typed.

Actual Behavior: /bin/sh: Hellotkterminal$: command not found

Possible Solutions: 1- Distinguish the output of a command from subsequent commands

2- Avoid the problem altogether by adding a newline to the end of each output that doesn't contain it already, and preferably also a terminator character to indicate the lack of an original newline. Sample output from macOS Terminal.app:

Screenshot 1402-05-08 at 11 08 22 PM

ShayanShahsiah avatar Jul 30 '23 19:07 ShayanShahsiah

By using subprocess.check_output, I think I've found the problem: printf does not add a new line character (\n), but echo does.

What to do here is check if the output endswith \n, then everything would be okay.

>>> import subprocess
>>> subprocess.check_output(["printf", "hello"])
b'hello'
>>> subprocess.check_output(["echo", "hello"])
b'hello\n'
>>>

lebao3105 avatar Oct 09 '23 12:10 lebao3105