Fix QProcess execution

This commit is contained in:
Vadim Kuznetsov 2022-03-08 00:15:37 +01:00
parent a416dead5c
commit 901f407d4a
7 changed files with 59 additions and 7 deletions

View File

@ -408,7 +408,10 @@ bool SpiceFile::recreateSubNetlist(QString *SpiceFile, QString *FileName)
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("PATH", env.value("PATH") );
SpicePrep->setProcessEnvironment(env);
SpicePrep->start(script.join(" "));
QString cmd = script.at(0);
QStringList script_args = script;
script_args.removeAt(0);
SpicePrep->start(cmd,script_args);
//QucsHelp->setCommunication(0);
if(SpicePrep->state()!=QProcess::Running&&

View File

@ -447,7 +447,10 @@ void Ngspice::slotSimulate()
SimProcess->setWorkingDirectory(workdir);
qDebug()<<workdir;
QString cmd = QString("\"%1\" %2 %3").arg(simulator_cmd,simulator_parameters,netfile);
SimProcess->start(cmd);
QStringList cmd_args = misc::parseCmdArgs(cmd);
QString ngsp_cmd = cmd_args.at(0);
cmd_args.removeAt(0);
SimProcess->start(ngsp_cmd,cmd_args);
emit started();
}

View File

@ -338,12 +338,12 @@ void XSPICE_CMbuilder::compileCMlib(QString &output)
output += QString("Working directory is %1\n").arg(cmdir);
QProcess *make = new QProcess();
make->setReadChannelMode(QProcess::MergedChannels);
make->setProcessChannelMode(QProcess::MergedChannels);
make->setWorkingDirectory(cmdir);
#ifdef __MINGW32__
make->start("mingw32-make.exe"); // For Unix
make->start("mingw32-make.exe",QStringList()); // For Unix
#else
make->start("make"); // For Unix
make->start("make",QStringList()); // For Unix
#endif
make->waitForFinished();
output += make->readAll();

View File

@ -19,6 +19,7 @@
#include "xyce.h"
#include "components/equation.h"
#include "main.h"
#include "misc.h"
/*!
@ -382,7 +383,10 @@ void Xyce::nextSimulation()
if (file.endsWith(".noise.cir")) Noisesim = true;
SimProcess->setWorkingDirectory(workdir);
QString cmd = QString("%1 %2 \"%3\"").arg(simulator_cmd,simulator_parameters,file);
SimProcess->start(cmd);
QStringList cmd_args = misc::parseCmdArgs(cmd);
QString xyce_cmd = cmd_args.at(0);
cmd_args.removeAt(0);
SimProcess->start(xyce_cmd,cmd_args);
} else {
output += "No simulations!\n"
"Exiting...\n";

View File

@ -442,6 +442,44 @@ VersionTriplet::VersionTriplet(const QString& version) {
}
}
QStringList misc::parseCmdArgs(const QString &program)
{
QStringList args;
QString tmp;
int quoteCount = 0;
bool inQuote = false;
// handle quoting. tokens can be surrounded by double quotes
// "hello world". three consecutive double quotes represent
// the quote character itself.
for (int i = 0; i < program.size(); ++i) {
if (program.at(i) == QLatin1Char('"')) {
++quoteCount;
if (quoteCount == 3) {
// third consecutive quote
quoteCount = 0;
tmp += program.at(i);
}
continue;
}
if (quoteCount) {
if (quoteCount == 1)
inQuote = !inQuote;
quoteCount = 0;
}
if (!inQuote && program.at(i).isSpace()) {
if (!tmp.isEmpty()) {
args += tmp;
tmp.clear();
}
} else {
tmp += program.at(i);
}
}
if (!tmp.isEmpty())
args += tmp;
return args;
}
VersionTriplet::VersionTriplet(){
major = minor = patch = 0;
}

View File

@ -87,6 +87,7 @@ namespace misc {
p->setIcon(icon);
p->setIconSize(pixmap.rect().size());
}
QStringList parseCmdArgs(const QString &program);
}
/*! handle the application version string

View File

@ -2321,7 +2321,10 @@ void QucsApp::slotOpenContent(const QModelIndex &idx)
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("PATH", env.value("PATH") );
Program->setProcessEnvironment(env);
Program->start(com.join(" "));
QString cmd = com.at(0);
QStringList com_args = com;
com_args.removeAt(0);
Program->start(cmd, com_args);
if(Program->state()!=QProcess::Running&&
Program->state()!=QProcess::Starting) {
QMessageBox::critical(this, tr("Error"),