-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Improve OS.execute()
(run a callback with the line contents every time a line is printed)
#216
Comments
Have you tried creating a TCP server on Godot and then OS.execute a client (python) script which can then talk with godot through the server instance? I tried it and it works. EDIT: Though, if you're not used to socket programming, then this might be difficult for you. |
I am not to familer with socket programming but I'm sure you could probably also run a simple http server on the python side then post to it from godot. the point of this proposal, is at the moment it requires alot of extra work and work arounds to make a usable solution to robustly call an outside executable. Thanks for the suggestion, it inspired using a http server . Which should be a good work around till this is hopefully improved upon. |
For some reason TCP is preferred over standard pipes, but as someone who barely knows how to use C++, communication with console apps written in this language becomes less than trivial, requiring argument processing (in my case, 3rd party string functions to handle splitting and type conversion) or a sockets implementation on the backend. I support proposals that amend |
Okay so I took a look at how, if even, it can be implemented and I have to be honest here, I could not find where the OS.execute is defined in the source code. You might think "ok", its probably in "OS" -> "os.cpp" file, but you'd be wrong. The header file "os.h" has a definition of "execute", which is not defined in the os.cpp" file. If the source code would make any fucking sense, then MAYBE I could contribute something myself. |
I think its defined per platform. I found the windows version here https://github.com/godotengine/godot/blob/master/platform/windows/os_windows.cpp |
It's platform specific, plus there is additional wrapper for the gdscript.
|
Okay, thanks. That's the code I was looking for. Now that I've realized that I can't understand a single line of that gibberish, I'm dropping any attempt to improve Godot by myself. |
OS.execute()
(run a callback with the line contents every time a line is printed)
There's godotengine/godot#8310 if any one wants to retake it. |
+ But at least |
I would also love to see stdin/out/err support for os.execute. Also would be nice allowing to read stdin of godot process. |
As potential references/libraries for this feature request:
|
I don't like the idea of adding a ton of unreadable parameters to |
Workaround for printing a character every second while command is running: func run_command() -> void:
var thread = Thread.new()
thread.start(_build)
while(thread.is_alive()):
OS.delay_msec(1000)
printraw(".")
thread.wait_to_finish()
func _build():
var outArray: Array = []
OS.execute('bash',['build'],outArray,true,false) |
Ran across this forum thread when trying to figure out how to make one of my slow The I would recommend looking some at the python subprocess APIs which from personal experience are very nice to use and have most platform specific concerns abstracted away. Godot's "execute" and "create_process" calls are very close to what we need, just missing a few features. |
Yes, since this is quite different from what's originally asked here. |
@lyuma , there's a pending PR using Tiny Process Librairy (godotengine/godot#66830) |
I would like to add another approach instead of reading line-for-line would be to read all output but add an additional argument for limiting the buffer to a certain amount of characters to prevent buffer overflow, and this will allow more than a single line to be read at a time, if the buffer limit happens to be greater than the most recent line length. Additionally, being able to write to standard input of the child process or to get the process id of the child would be other useful additions. |
I would like to point out according to Microsoft Documentation, UWP supports |
UWP support was dropped in 4.x, so it doesn't matter what is supported on this platform.
Most standard way of doing in is probably |
I didn't know UWP was dropped; that makes sense then I guess. Wouldn't what you suggest with on demand read/write be a risk for buffer overflow? That's why I mentioned it being optional to have a buffer limit for apps that need it. |
No. Usually, a pipe like this is blocking (I think on Windows it's the only supported option), so if the internal pipe buffer is full, the app will be waiting for the other end to take some data out. |
@bruvzg I think I must be misunderstanding you somewhere right now, because I wrote my own process library, and Unix-likes and Windows alike it is not blocking, though I am using multi-threading to make it not block, (so I guess you mean blocks current thread? and not all threads? You said blocking is the only option on Windows which makes it sound like all threads will be blocked and I know this is not so, so maybe you mean the former and not the latter?) Just want to make sure I am understanding you correctly. Of course it blocks the calling thread on Windows, but it shouldn't block outside threads. Here's the library I wrote in case you were wondering: https://github.com/time-killer-games/xproc I would like to help contribute to the |
Only output write calls (in the app) and pipe read calls (in the engine) are blocking. It's not blocking other threads or process in general (if it's not outputting anything). |
With godotengine/godot#89206, I think this is resolved. I was able to use the new pipe API to achieve what is requested in this proposal. A callback can be implemented manually. Since I already have a nice wrapper, I could make it into an addon. |
Equivalent functionality was implemented by godotengine/godot#89206, closing. |
Describe the project you are working on:
A application that calls a console executable to encode video
Describe the problem or limitation you are having in your project:
When using os.execute you can get the data back using blocking mode or non-blocking when using threads but only when the application is closed/completed. At least as far as I know there is no way to get the data line by line while the application is running.
Describe how this feature / enhancement will help you overcome this problem or limitation:
It would be great if in either blocking or non blocking for every line printed by the exe call a function with the new line as its printed in realtime.
this would make it super easy to call and check progress on external executables
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
for example it should work like
Describe implementation detail for your proposal (in code), if possible:
If this enhancement will not be used often, can it be worked around with a few lines of script?:
no this would need to be implemented in core as it not something that can be changed in gdscript
Is there a reason why this should be core and not an add-on in the asset library?:
as noted above this is already a core feature that would be enhanced
The text was updated successfully, but these errors were encountered: