From 253db95cba25a9f9a713bcd18446ff58fdd8bd35 Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Thu, 21 Sep 2017 17:44:53 -0300 Subject: [PATCH] OS::execute can now read from stderr too when executing with a pipe. --- core/os/os.h | 2 +- drivers/unix/os_unix.cpp | 8 ++++++-- drivers/unix/os_unix.h | 2 +- platform/windows/os_windows.cpp | 2 +- platform/windows/os_windows.h | 2 +- platform/winrt/os_winrt.cpp | 2 +- platform/winrt/os_winrt.h | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/os/os.h b/core/os/os.h index 5ee24c9585c..41b1956dc57 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -197,7 +197,7 @@ public: virtual String get_installed_templates_path() const { return ""; } virtual String get_executable_path() 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) = 0; + 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) = 0; virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_ID() const; diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 3bd27f06031..658bb4fbaf1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -330,7 +330,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) { @@ -342,7 +342,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 85ac908fc8d..bad1188ae7a 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; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bf9cdee5cf9..fdbaf7810f6 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1901,7 +1901,7 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -Error OS_Windows::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OS_Windows::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) { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index ddd082b3cf8..5889420b547 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -241,7 +241,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; diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp index 43c2fbaa982..90a33ef91b9 100644 --- a/platform/winrt/os_winrt.cpp +++ b/platform/winrt/os_winrt.cpp @@ -771,7 +771,7 @@ void OSWinrt::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -Error OSWinrt::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { +Error OSWinrt::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) { return FAILED; }; diff --git a/platform/winrt/os_winrt.h b/platform/winrt/os_winrt.h index 0feb7d21659..121b1bed18d 100644 --- a/platform/winrt/os_winrt.h +++ b/platform/winrt/os_winrt.h @@ -226,7 +226,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 bool has_environment(const String &p_var) const;