From: Enrico Forestieri Date: Mon, 22 Aug 2011 01:39:49 +0000 (+0000) Subject: Fix #7715 (Lyx 2.0.0 doesn't work with Mathematica 8: call to 'math' problem?) X-Git-Tag: 2.1.0beta1~2804 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f3f38f492b032aa7648de3fa5bf8234f8aa874b7;p=features.git Fix #7715 (Lyx 2.0.0 doesn't work with Mathematica 8: call to 'math' problem?) The fix also allows to execute again batch files when using runCommand. Unfortunately, this is still not possible with QProcess as that code is not under our control. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39504 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index dc4e3cd5bd..e54b92ab9e 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -851,6 +851,10 @@ cmd_ret const runCommand(string const & cmd) SECURITY_ATTRIBUTES security; HANDLE in, out; FILE * inf = 0; + string command; + string const infile = trim(split(cmd, command, '<'), " \""); + string const cmdarg = "/c " + command; + string const comspec = getEnv("COMSPEC"); security.nLength = sizeof(SECURITY_ATTRIBUTES); security.bInheritHandle = TRUE; @@ -864,11 +868,17 @@ cmd_ret const runCommand(string const & cmd) startup.dwFlags = STARTF_USESTDHANDLES; startup.hStdError = GetStdHandle(STD_ERROR_HANDLE); - startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + startup.hStdInput = infile.empty() + ? GetStdHandle(STD_INPUT_HANDLE) + : CreateFile(infile.c_str(), GENERIC_READ, + FILE_SHARE_READ, &security, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); startup.hStdOutput = out; - if (CreateProcess(0, (LPTSTR)cmd.c_str(), &security, &security, - TRUE, CREATE_NO_WINDOW, 0, 0, &startup, &process)) { + if (startup.hStdInput != INVALID_HANDLE_VALUE && + CreateProcess(comspec.c_str(), (LPTSTR)cmdarg.c_str(), + &security, &security, TRUE, CREATE_NO_WINDOW, + 0, 0, &startup, &process)) { CloseHandle(process.hThread); fno = _open_osfhandle((long)in, _O_RDONLY); @@ -899,6 +909,8 @@ cmd_ret const runCommand(string const & cmd) #if defined (_WIN32) WaitForSingleObject(process.hProcess, INFINITE); + if (!infile.empty()) + CloseHandle(startup.hStdInput); CloseHandle(process.hProcess); int const pret = fclose(inf); #elif defined (HAVE_PCLOSE)