This is code adapted from #89206’s example, which only modifies the program that is executed, but it is now completely useless, and it does not write any characters in the TextEdit.
extends Control
var pipe
var thread
func _ready():
var info = OS.execute_with_pipe("python.exe", [])
pipe = info["stdio"]
thread = Thread.new()
thread.start(_thread_func)
get_window().close_requested.connect(clean_func)
func _thread_func():
while pipe.is_open() and pipe.get_error() == OK:
_add_char.call_deferred(char(pipe.get_8()))
print(pipe.get_error())
func _add_char(c):
$TextEdit.text += c
$TextEdit.scroll_vertical = $TextEdit.get_v_scroll_bar().max_value
func _on_line_edit_text_submitted(new_text: String) -> void:
var cmd = new_text + "\n"
var buffer = cmd.to_utf8_buffer()
pipe.store_buffer(buffer)
$LineEdit.text = ""
func clean_func():
pipe.close()
thread.wait_to_finish()
Btw I’m also on Linux. I was only able to capture python interactive shell to file with 3> or &>, meaning it’s some of its output is not on stdio. If I tried to do a redirect to stdio In Godot with something like 3>&1 it still wouldn’t capture the python shell output, but it would crash the game if you did an input.
Hi, I have it working on Linux, though not sure what was causing all my problems before. If anyone wants download attached project. I am using bash as the shell.
When you run it, you can type a command in the LineEdit box and press Enter. E.g. type something pwd or ls. I also tried ping yahoo.com works but no way to break out of it (ie ctrl-c does now work). Pretty cool though.
I had the same result with bash and sh, but the original post was trying to use the python shell, which doesn’t use the standard streams, I have only confirmed this by using Linux redirects greater then the stderr stream.