MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / execCommand

Method execCommand

src/plugins/debugger/runner/runner.cpp:176–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool Runner::execCommand(const RunCommandInfo &info)
177{
178 bool ret = false;
179 QString retMsg = tr("Error: execute command error! The reason is unknown.\n");
180 QProcess process;
181 process.setWorkingDirectory(info.workingDir);
182 process.setEnvironment(info.envs);
183
184 QString startMsg = tr("Start execute command: \"%1\" \"%2\" in workspace \"%3\".\n")
185 .arg(info.program, info.arguments.join(" "), info.workingDir);
186
187 connect(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
188 [&](int exitcode, QProcess::ExitStatus exitStatus) {
189 if (0 == exitcode && exitStatus == QProcess::ExitStatus::NormalExit) {
190 ret = true;
191 retMsg = tr("The process \"%1\" exited normally.\n").arg(process.program());
192 } else if (exitStatus == QProcess::NormalExit) {
193 ret = false;
194 retMsg = tr("The process \"%1\" exited with code %2.\n")
195 .arg(process.program(), QString::number(exitcode));
196 } else {
197 ret = false;
198 retMsg = tr("The process \"%1\" crashed.\n")
199 .arg(process.program());
200 }
201 });
202
203 connect(&process, &QProcess::readyReadStandardOutput, [&]() {
204 process.setReadChannel(QProcess::StandardOutput);
205 while (process.canReadLine()) {
206 QString line = QString::fromUtf8(process.readLine());
207 outputMsg(process.pid(), line, OutputPane::OutputFormat::StdOut);
208 }
209 });
210
211 connect(&process, &QProcess::readyReadStandardError, [&]() {
212 process.setReadChannel(QProcess::StandardError);
213 while (process.canReadLine()) {
214 QString line = QString::fromUtf8(process.readLine());
215 outputMsg(process.pid(), line, OutputPane::OutputFormat::StdErr);
216 }
217 });
218
219 process.start(info.program, info.arguments);
220 quint64 pid = process.pid();
221 QMetaObject::invokeMethod(AppOutputPane::instance(), "createApplicationPane",
222 Q_ARG(const QString &, QString::number(pid)), Q_ARG(QString, info.program));
223 outputMsg(pid, startMsg, OutputPane::OutputFormat::NormalMessage);
224 process.waitForFinished(-1);
225
226 AppOutputPane::instance()->setProcessFinished(QString::number(pid));
227
228 outputMsg(pid, retMsg, ret ? OutputPane::OutputFormat::NormalMessage : OutputPane::OutputFormat::StdErr);
229
230 QString endMsg = tr("Execute command finished.\n");
231 outputMsg(pid, endMsg, OutputPane::OutputFormat::NormalMessage);
232
233 return ret;

Callers

nothing calls this directly

Calls 10

connectFunction · 0.85
numberClass · 0.85
canReadLineMethod · 0.80
pidMethod · 0.80
setProcessFinishedMethod · 0.80
setWorkingDirectoryMethod · 0.45
setEnvironmentMethod · 0.45
programMethod · 0.45
readLineMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected