mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 13:43:15 +00:00
Added an exit code to the blocking mode of OS::execute
Updated documentation accordingly. Fixes #31881.
This commit is contained in:
parent
084481b79d
commit
b4c927b514
@ -481,15 +481,18 @@ Error _OS::shell_open(String p_uri) {
|
||||
int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) {
|
||||
|
||||
OS::ProcessID pid = -2;
|
||||
int exitcode = 0;
|
||||
List<String> args;
|
||||
for (int i = 0; i < p_arguments.size(); i++)
|
||||
args.push_back(p_arguments[i]);
|
||||
String pipe;
|
||||
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, NULL, p_read_stderr);
|
||||
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
|
||||
p_output.clear();
|
||||
p_output.push_back(pipe);
|
||||
if (err != OK)
|
||||
return -1;
|
||||
else if (p_blocking)
|
||||
return exitcode;
|
||||
else
|
||||
return pid;
|
||||
}
|
||||
|
@ -105,11 +105,11 @@
|
||||
This method has slightly different behavior based on whether the [code]blocking[/code] mode is enabled.
|
||||
If [code]blocking[/code] is [code]true[/code], the Godot thread will pause its execution while waiting for the process to terminate. The shell output of the process will be written to the [code]output[/code] array as a single string. When the process terminates, the Godot thread will resume execution.
|
||||
If [code]blocking[/code] is [code]false[/code], the Godot thread will continue while the new process runs. It is not possible to retrieve the shell output in non-blocking mode, so [code]output[/code] will be empty.
|
||||
The return value also depends on the blocking mode. When blocking, the method will return -2 (no process ID information is available in blocking mode). When non-blocking, the method returns a process ID, which you can use to monitor the process (and potentially terminate it with [method kill]). If the process forking (non-blocking) or opening (blocking) fails, the method will return [code]-1[/code].
|
||||
The return value also depends on the blocking mode. When blocking, the method will return an exit code of the process. When non-blocking, the method returns a process ID, which you can use to monitor the process (and potentially terminate it with [method kill]). If the process forking (non-blocking) or opening (blocking) fails, the method will return [code]-1[/code] or another exit code.
|
||||
Example of blocking mode and retrieving the shell output:
|
||||
[codeblock]
|
||||
var output = []
|
||||
OS.execute("ls", ["-l", "/tmp"], true, output)
|
||||
var exit_code = OS.execute("ls", ["-l", "/tmp"], true, output)
|
||||
[/codeblock]
|
||||
Example of non-blocking mode, running another instance of the project and storing its process ID:
|
||||
[codeblock]
|
||||
|
@ -314,7 +314,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
|
||||
}
|
||||
int rv = pclose(f);
|
||||
if (r_exitcode)
|
||||
*r_exitcode = rv;
|
||||
*r_exitcode = WEXITSTATUS(rv);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user