Saadmairaj / tkterminal

Terminal widget for Tkinter library.
https://pypi.org/project/tkterminal
Apache License 2.0
58 stars 6 forks source link

Tkterminal interprets output without newline as part of next command #17

Open ShayanShahsiah opened 1 year ago

ShayanShahsiah commented 1 year ago

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
lebao3105 commented 11 months ago

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'
>>>