int Systemcall::startscript(Starttype how, string const & what,
string const & path, bool process_events)
{
- lyxerr << "\nRunning: " << what << endl;
+ LYXERR(Debug::INFO,"Running: " << what);
string infile;
string outfile;
string errfile;
- QString cmd = QString::fromLocal8Bit(
+ QString const cmd = QString::fromLocal8Bit(
parsecmd(what, infile, outfile, errfile).c_str());
SystemcallPrivate d(infile, outfile, errfile);
- d.startProcess(cmd, path);
- if (!d.waitWhile(SystemcallPrivate::Starting, process_events, -1)) {
+ d.startProcess(cmd, path, how == DontWait);
+ if (how == DontWait && d.state == SystemcallPrivate::Running) {
+ return 0;
+ }
+ if (d.state == SystemcallPrivate::Error
+ || !d.waitWhile(SystemcallPrivate::Starting, process_events, -1)) {
LYXERR0("Systemcall: '" << cmd << "' did not start!");
LYXERR0("error " << d.errorMessage());
return 10;
}
- if (how == DontWait) {
- QProcess* released = d.releaseProcess();
- (void) released; // TODO who deletes it?
- return 0;
- }
-
if (!d.waitWhile(SystemcallPrivate::Running, process_events,
os::timeout_min() * 60 * 1000)) {
LYXERR0("Systemcall: '" << cmd << "' did not finish!");
}
-void SystemcallPrivate::startProcess(QString const & cmd, string const & path)
+void SystemcallPrivate::startProcess(QString const & cmd, string const & path, bool detached)
{
cmd_ = cmd;
- if (process_) {
+ if (detached) {
+ state = SystemcallPrivate::Running;
+ if (!QProcess::startDetached(toqstr(latexEnvCmdPrefix(path)) + cmd_)) {
+ state = SystemcallPrivate::Error;
+ return;
+ }
+ QProcess* released = releaseProcess();
+ delete released;
+ } else if (process_) {
state = SystemcallPrivate::Starting;
process_->start(toqstr(latexEnvCmdPrefix(path)) + cmd_);
}
return state != Error;
}
- // process events while waiting whith timeout
+ // process events while waiting with timeout
QTime timer;
timer.start();
while (state == waitwhile && state != Error && !timedout) {