Running shell command and capturing the output

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek
:warning: Old Version Published before Godot 3 was released.

Hi
After little fight with Kivy I have decide to rewrite my company inside render-manager in godot for simpler UI design and… Godot it’s great :wink:

But I have little problem, executing shell commands is very simple but how can I capture output from console? It’s needed for controlling progress and errors. It’s even possible?

Never tried but can’t you redirect the output to a file in user:// path?

eons | 2017-01-09 23:33

:bust_in_silhouette: Reply From: eska

Hand an array as the fourth argument to OS.execute. Each line of output will be added as an element to that array. For example:

var output = []
OS.execute( 'grep', ['-Irn', 'pattern', '.'], true, output )
for line in output:
	print( line )

Make sure to create the output array using [] and not Array(), only arrays created using [] are shared (see issue #5277)

Is there any way to know if process has finished when using non-blocking exec?

Daniel Lewan | 2017-03-31 19:27