From ee1c8c5c25d25dfa42120125a8a45dc9831ee412 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:23:48 +0200 Subject: 5.14 --- wx+/shell_execute.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'wx+/shell_execute.h') diff --git a/wx+/shell_execute.h b/wx+/shell_execute.h index a07f40cb..acf84794 100644 --- a/wx+/shell_execute.h +++ b/wx+/shell_execute.h @@ -8,19 +8,21 @@ #define EXECUTE_HEADER_23482134578134134 #include +#include +#include +#include #include #ifdef FFS_WIN #include -#include -#include +//#include #include //includes "windows.h" -//#include #elif defined FFS_LINUX || defined FFS_MAC -#include -#include -#include +#include +#include //::system() +//#include +//#include #endif @@ -28,14 +30,14 @@ namespace zen { //launch commandline and report errors via popup dialog //windows: COM needs to be initialized before calling this function! -namespace -{ enum ExecutionType { EXEC_TYPE_SYNC, EXEC_TYPE_ASYNC }; +namespace +{ void shellExecute(const Zstring& command, ExecutionType type = EXEC_TYPE_ASYNC) { #ifdef FFS_WIN @@ -78,32 +80,30 @@ void shellExecute(const Zstring& command, ExecutionType type = EXEC_TYPE_ASYNC) if (execInfo.hProcess) { + ZEN_ON_SCOPE_EXIT(::CloseHandle(execInfo.hProcess)); + if (type == EXEC_TYPE_SYNC) ::WaitForSingleObject(execInfo.hProcess, INFINITE); - ::CloseHandle(execInfo.hProcess); } #elif defined FFS_LINUX || defined FFS_MAC + /* + we cannot use wxExecute due to various issues: + - screws up encoding on OS X for non-ASCII characters + - does not provide any reasonable error information + - uses a zero-sized dummy window as a hack to keep focus which leaves a useless empty icon in ALT-TAB list + */ + if (type == EXEC_TYPE_SYNC) { //Posix::system - execute a shell command int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect... if (rv == -1 || WEXITSTATUS(rv) == 127) //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)" - { wxMessageBox(_("Invalid command line:") + L"\n" + utfCvrtTo(command)); - return; - } } else - { - // ! unfortunately it seems there is no way on Linux to get a failure notification for calling an invalid command line asynchronously ! - - //by default wxExecute uses a zero sized dummy window as a hack to keep focus which leaves a useless empty icon in ALT-TAB list - //=> use wxEXEC_NODISABLE and roll our own window disabler! (see comment in app.cpp: void *wxGUIAppTraits::BeforeChildWaitLoop()) - wxWindowDisabler dummy; //disables all top level windows - wxExecute(utfCvrtTo(command), wxEXEC_ASYNC | wxEXEC_NODISABLE); - wxLog::FlushActive(); //show wxWidgets error messages (if any) - } + async([=] { /*int rv = */ ::system(command.c_str()); }); + //unfortunately we are not allowed to show a wxMessageBox from a worker thread #endif } } -- cgit