#include <config.h>
#include "support/debug.h"
+#include "support/environment.h"
+#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/Systemcall.h"
#include "support/os.h"
#include "support/ProgressInterface.h"
+#include "LyXRC.h"
#include <cstdlib>
#include <iostream>
// Reuse of instance
#ifndef USE_QPROCESS
int Systemcall::startscript(Starttype how, string const & what,
- bool /*process_events*/)
+ std::string const & path, bool /*process_events*/)
{
- string command = what;
+ string command;
+ string const texinputs = os::latex_path_list(
+ replaceCurdirPath(path, lyxrc.texinputs_prefix));
+ string const sep = string(1, os::path_separator(os::TEXENGINE));
+ string const env = getEnv("TEXINPUTS");
+
+ switch (os::shell()) {
+ case os::UNIX:
+ command = path.empty() || lyxrc.texinputs_prefix.empty() ? what
+ : "env TEXINPUTS='." + sep + texinputs
+ + sep + env + "' " + what;
+ break;
+ case os::CMD_EXE:
+ command = path.empty() || lyxrc.texinputs_prefix.empty() ? what
+ : "set TEXINPUTS=." + sep + texinputs
+ + sep + env + " & " + what;
+ break;
+ }
if (how == DontWait) {
switch (os::shell()) {
-int Systemcall::startscript(Starttype how, string const & what, bool process_events)
+int Systemcall::startscript(Starttype how, string const & what,
+ string const & path, bool process_events)
{
string outfile;
QString cmd = toqstr(parsecmd(what, outfile));
SystemcallPrivate d(outfile);
- d.startProcess(cmd);
+ d.startProcess(cmd, path);
if (!d.waitWhile(SystemcallPrivate::Starting, process_events, -1)) {
LYXERR0("Systemcall: '" << cmd << "' did not start!");
LYXERR0("error " << d.errorMessage());
out_index_(0),
err_index_(0),
out_file_(of),
+ texinputs_(getEnv("TEXINPUTS")),
process_events_(false)
{
if (!out_file_.empty()) {
-void SystemcallPrivate::startProcess(const QString& cmd)
+void SystemcallPrivate::startProcess(QString const & cmd, string const & path)
{
cmd_ = cmd;
if (process_) {
+ if (!path.empty() && !lyxrc.texinputs_prefix.empty()) {
+ string const texinputs = os::latex_path_list(
+ replaceCurdirPath(path, lyxrc.texinputs_prefix));
+ string const sep = string(1,
+ os::path_separator(os::TEXENGINE));
+ string const prefix = "." + sep + texinputs + sep;
+ if (prefixIs(texinputs_, prefix))
+ texinputs_.clear();
+ else
+ setEnv("TEXINPUTS", prefix + texinputs_);
+ }
state = SystemcallPrivate::Starting;
- process_->start(cmd_);
+ if (os::shell() == os::CMD_EXE)
+ process_->start(QLatin1String("cmd /d /c ") + cmd_);
+ else
+ process_->start(cmd_);
}
}
SystemcallPrivate::~SystemcallPrivate()
{
+ if (!texinputs_.empty())
+ setEnv("TEXINPUTS", texinputs_);
+
if (out_index_) {
out_data_[out_index_] = '\0';
out_index_ = 0;