From 4b695c3bdf562d55fb617a6c48eb5c1701b81325 Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Tue, 3 Oct 2017 15:09:04 -0300 Subject: OS::execute can now read from stderr too when executing with a pipe --- drivers/unix/os_unix.cpp | 8 ++++++-- drivers/unix/os_unix.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 29fe73f170..e0a62b316d 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -285,7 +285,7 @@ uint64_t OS_Unix::get_ticks_usec() const { return longtime; } -Error OS_Unix::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OS_Unix::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { if (p_blocking && r_pipe) { @@ -297,7 +297,11 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo argss += String(" \"") + p_arguments[i] + "\""; } - argss += " 2>/dev/null"; //silence stderr + if (read_stderr) { + argss += " 2>&1"; // Read stderr too + } else { + argss += " 2>/dev/null"; //silence stderr + } FILE *f = popen(argss.utf8().get_data(), "r"); ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 1cc44c0ffd..87e73534c4 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -97,7 +97,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL); + virtual Error execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); virtual Error kill(const ProcessID &p_pid); virtual int get_process_id() const; -- cgit v1.2.3