From ce74af9ec0b5a2e973ab58d8392a9d3a8f4a1b7a Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 23 Aug 2011 18:51:41 +0000 Subject: [PATCH] Fix #7715 (Lyx 2.0.0 doesn't work with Mathematica 8: call to 'math' problem?) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39514 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/filetools.cpp | 26 ++++++++++++++++++++++---- status.20x | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index dc4e3cd5bd..dc01fcda86 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -851,6 +851,16 @@ cmd_ret const runCommand(string const & cmd) SECURITY_ATTRIBUTES security; HANDLE in, out; FILE * inf = 0; + bool err2out = false; + string command; + string const infile = trim(split(cmd, command, '<'), " \""); + command = rtrim(command); + if (suffixIs(command, "2>&1")) { + command = rtrim(command, "2>&1"); + err2out = true; + } + string const cmdarg = "/c " + command; + string const comspec = getEnv("COMSPEC"); security.nLength = sizeof(SECURITY_ATTRIBUTES); security.bInheritHandle = TRUE; @@ -863,12 +873,18 @@ cmd_ret const runCommand(string const & cmd) startup.cb = sizeof(STARTUPINFO); startup.dwFlags = STARTF_USESTDHANDLES; - startup.hStdError = GetStdHandle(STD_ERROR_HANDLE); - startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + startup.hStdError = err2out ? out : GetStdHandle(STD_ERROR_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 +915,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) diff --git a/status.20x b/status.20x index 65f2e32cf4..0e934dc1fa 100644 --- a/status.20x +++ b/status.20x @@ -252,6 +252,8 @@ What's new - With aspell backend split words on hard hyphens to check parts separately because hyphen is not allowed to be part of a word (bug 7660). +- On Windows, fix call to Computer Algebra System programs (bug 7715). + * ADVANCED FIND AND REPLACE -- 2.39.5