-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement pipe API for executed processes IO redirection. #89206
Conversation
a39c5ee
to
8a5da44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on Windows and it works great.
…d stdio. Implement `pipe://*` path handling for creation of named pipes.
Thanks! |
Unless I'm missing something, there is no way to get the result code from finished process 🤔 |
Maybe check tiny-process-library techniques? |
Thank you so very much for this! Life saver!!! :D |
PLEASE IGNORE THIS COMMENT. I TESTED AGAIN (NO UPDATES NOR CHANGES) AND FOR WHATEVER REASON, IT"S WORKING. I''LEAVE COMMENT IN CASE IT COMES BACK. THANKS Hi I am testing on Linux : Kubuntu 23.10, KDE Plasma Version: 5.27.8 Using the samples, I can get the named pipes to work. However I cannot get the Process Redirect to work. I changed the execute command to Here is the code I run: extends Control
var pipe
var thread
func _ready():
$TextEdit.text = "Textedit "
$LineEdit.text = "Lineedit "
# start terminal and open pipes
var info
if OS.get_name() == "Windows":
info = OS.execute_with_pipe("cmd.exe", [])
else:
var args = ["-c","uname"]
info = OS.execute_with_pipe("/usr/bin/bash", args)
pass
pipe = info["stdio"]
print(info)
thread = Thread.new()
thread.start(_thread_func)
get_window().close_requested.connect(clean_func)
func _thread_func():
# read stdin and add to TextEdit.
while pipe.is_open() and pipe.get_error() == OK:
_add_char.call_deferred(char(pipe.get_8()))
func _add_char(c):
print(c)
$TextEdit.text += c
$TextEdit.scroll_vertical = $TextEdit.get_v_scroll_bar().max_value
func _on_line_edit_text_submitted(new_text: String) -> void:
# send command to stdin.
var cmd = new_text + "\n"
var buffer = cmd.to_utf8_buffer()
pipe.store_buffer(buffer)
$LineEdit.text = ""
func clean_func():
# close pipe and cleanup.
pipe.close()
thread.wait_to_finish()
|
PLEASE IGNORE THIS COMMENT. I TESTED AGAIN (NO UPDATES NOR CHANGES) AND FOR WHATEVER REASON, IT"S WORKING. I''LEAVE COMMENT IN CASE IT COMES BACK. THANKS Additional Info: I get this error in the output when it hits a breakpoint right after `info = OS.execute_with_pipe("/usr/bin/bash", args)
Also |
OS.execute_with_pipe
method to run process with redirected stdio.stdout
andstderr
.stdin
.FileAccess
API, instead of limiting it to theString
.pipe://*
path handling for creation of named pipes.Implemented on Windows and Unix (tested on macOS, but should work on Linux/Android as well).
Samples - click to expand
Process redirect:
Named pipe (server):
Named pipe (client):
OS.execute()
(run a callback with the line contents every time a line is printed) godot-proposals#216.