unix = True
if stderr2stdout:
pipe = subprocess.Popen(cmd, shell=unix, close_fds=unix, stdin=subprocess.PIPE, \
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, env=os.environ)
cmd_stdout = pipe.communicate()[0]
else:
pipe = subprocess.Popen(cmd, shell=unix, close_fds=unix, stdin=subprocess.PIPE, \
- stdout=subprocess.PIPE, universal_newlines=True)
+ stdout=subprocess.PIPE, universal_newlines=True, env=os.environ)
(cmd_stdout, cmd_stderr) = pipe.communicate()
if cmd_stderr:
sys.stderr.write(cmd_stderr)
#include <config.h>
+#include "LyXRC.h"
+
#include "support/ForkedCalls.h"
#include "support/debug.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/Timeout.h"
+#include "support/environment.h"
#include "support/bind.h"
using namespace std;
+#ifdef USE_MACOSX_PACKAGING
+#include <crt_externs.h>
+#endif
namespace lyx {
return 1;
// Make sure that a V2 python is run, if available.
- string const line = cmd_prefix_ +
+ string const line =
+#ifndef USE_MACOSX_PACKAGING
+ cmd_prefix_ +
+#endif
(prefixIs(command_, "python -tt")
? os::python() + command_.substr(10) : command_);
lyxerr << '\t'<< *ait << '\n';
lyxerr << "</command>" << endl;
}
+#ifdef USE_MACOSX_PACKAGING
+ string path = getEnv("PATH");
+
+ // Combine TEXINPUTS prefix and environment
+ string ptex = getEnv("TEXINPUTS");
+ if (!lyxrc.texinputs_prefix.empty()) {
+ string const texinputs = lyxrc.texinputs_prefix + ":" + ptex;
+ setEnv("TEXINPUTS", texinputs);
+ }
+
+ char ** var = *_NSGetEnviron();
+ // See #9308 - "LyX cannot work properly in Yosemite"
+ // This is a workaround for the POSIX incompatibility of Yosemite
+ // Duplicate the environment.
+ // Otherwise it's not passed when code inside of bundles
+ // forks a child and executes a sub-program.
+ vector<char *> envp;
+ for (; *var != 0; ++var) {
+ if (lyxerr.debugging(Debug::DEBUG)) {
+ lyxerr << "env: " << *var << '\n';
+ }
+ envp.push_back(strdup(*var));
+ }
+ envp.push_back(0);
+ envp.push_back(0);
+
+ vector<char *> cmds;
+ if (0 == strchr(argv[0], '/')) {
+ while (!path.empty()) {
+ string element;
+ path = split(path,element,':');
+ if (!suffixIs(element,'/')) element += "/";
+ element += argv[0];
+ if (lyxerr.debugging(Debug::GRAPHICS)) {
+ lyxerr << "try: " << element.data() << '\n';
+ }
+ cmds.push_back(strdup(element.data()));
+ }
+ }
+ cmds.push_back(0);
+ pid_t const cpid = ::fork();
+ if (cpid == 0) {
+ // Child
+ if (0 == strchr(argv[0], '/')) {
+ vector<char *>::iterator cit = cmds.begin();
+ vector<char *>::iterator const cend = cmds.end();
+ for (; cit != cend; ++cit) {
+ if (*cit)
+ execve(*cit, &*argv.begin(), &*envp.begin());
+ }
+ } else {
+ execve(argv[0], &*argv.begin(), &*envp.begin());
+ }
+ // If something goes wrong, we end up here
+ lyxerr << "execvp of \"" << command_ << "\" failed: "
+ << strerror(errno) << endl;
+ _exit(1);
+ }
+#else
pid_t const cpid = ::fork();
if (cpid == 0) {
// Child
<< strerror(errno) << endl;
_exit(1);
}
+#endif
#else
// Windows
}
#endif
+#ifdef USE_MACOSX_PACKAGING
+ // Free duplicated command candidates.
+ vector<char *>::iterator cit = cmds.begin();
+ vector<char *>::iterator const cend = cmds.end();
+ for (; cit != cend; ++cit)
+ if (*cit) free(*cit);
+ // Free duplicated environment.
+ vector<char *>::iterator eit = envp.begin();
+ vector<char *>::iterator const eend = envp.end();
+ for (; eit != eend; ++eit)
+ if (*eit) free(*eit);
+ // Restore TEXINPUTS.
+ setEnv("TEXINPUTS", ptex);
+#endif
+
if (cpid < 0) {
// Error.
lyxerr << "Could not fork: " << strerror(errno) << endl;
QProcess* released = releaseProcess();
delete released;
} else if (process_) {
+#ifdef Q_OS_MAC
+ process_->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
+ if (!lyxrc.texinputs_prefix.empty()) {
+ QProcessEnvironment environ = process_->processEnvironment();
+ string const texinputs = fromqstr(environ.value("TEXINPUTS"));
+ string const texinputs_prefix = os::latex_path_list(
+ path.empty() ? lyxrc.texinputs_prefix : replaceCurdirPath(path, lyxrc.texinputs_prefix));
+ environ.insert("TEXINPUTS", toqstr(".:" + texinputs_prefix + ':' + texinputs));
+ process_->setProcessEnvironment(environ);
+ }
+ if (!lyxrc.path_prefix.empty()) {
+ QProcessEnvironment environ = process_->processEnvironment();
+ string const path = fromqstr(environ.value("PATH"));
+ environ.insert("PATH", toqstr(lyxrc.path_prefix + ':' + path));
+ process_->setProcessEnvironment(environ);
+ }
+ state = SystemcallPrivate::Starting;
+ process_->start(cmd_);
+#else
state = SystemcallPrivate::Starting;
process_->start(toqstr(latexEnvCmdPrefix(path)) + cmd_);
+#endif
}
}