tkterminal
tkterminal copied to clipboard
Tkterminal interprets output without newline as part of next command
Steps to Reproduce:
- Run
printf Hello
in atkterminal
instance (I'm usingshell=True
) - The output is:
Hellotkterminal$
- 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:
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'
>>>