Solved Qprocess: how to debug the full command send/used to start the process?
-
hi there,
I can use something like this to launch a process:
I would like to debug/see the full command used to launch the process.There is "arguments()" But this gives me only the list of command options.
proc = new QProcess(); proc->start("/path/to/executable" , QStringList() << "option1" << "option2"; qDebug() << "Arguments: " << proc->arguments();
What I am asking is if there is a proc->showFullCommand(); tip or how to get this information.
In the documentation I could not find something like this.thx in advance
-
@ademmler said in Qprocess: how to debug the full command send/used to start the process?:
arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:
<< "-aavector" << "yes"
-
@ademmler said in Qprocess: how to debug the full command send/used to start the process?:
I would like to debug/see the full command used to launch the process.
Hi,
qDebug() << proc->program << " " << proc->arguments();
returns
"/path/to/executable" ("option1", "option2")
And if you parse the
QStringList
with your args, you could create an output like the "real" command would look like.
Something like:/path/to/executable -option1 -option2
-
@Pl45m4 thx for the nice approach. But this is still a guess.
I have doubts that Process creates the proper command in my case.
Hence I want to see what is fired up there ...Maybe somebody can point me to the right spot in the debugger ...
I am aware, that this peace of code is neither "not perfect QT" nor my real application.
It is a sketch to test and simulate my issue in a minimal version.#include "mainwindow.h" #include "ui_mainwindow.h" using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_startButton_released() { /* clear text report */ ui->textEdit->clear(); QString fileName = QFileDialog::getOpenFileName(this, tr("Open Input Image"), "~", tr("Open file") + " (*.jpg *.jpeg *.tif *.tiff *.pdf)"); QFile fi(fileName); if(fi.exists()) { slotDoPdfRaster(fileName); // I know I should use a connect / emit here! } else { qDebug() << "No file opend"; } } void MainWindow::slotDoPdfRaster(QString input) { QString inputFile = input; QString outputFile = input + ".tiff"; QString report = input + ".devn"; QDir rep; QDir in; QDir out; int ripResolutionLow = 50; ui->statusbar->showMessage("Start rip ...", 3); QString program = "pdfraster64"; QStringList arguments; arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile); myProcess = new QProcess(this); qDebug() << "Rip program: " + program; qDebug() << "Rip arguments: " + arguments.join(" "); myProcess->start(program, arguments); /* show output */ connect(myProcess, SIGNAL(readyReadStandardOutput()),this, SLOT(rightMessage()) ); connect(myProcess, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()) ); ui->statusbar->showMessage("Idle ...", 0); } // show right message void MainWindow::rightMessage() { QByteArray strdata = myProcess->readAllStandardOutput(); ui->textEdit->setTextColor(Qt::black); ui->textEdit->append(strdata); } // show wrong message void MainWindow::wrongMessage() { QByteArray strdata = myProcess->readAllStandardError(); ui->textEdit->setTextColor(Qt::red); ui->textEdit->append(strdata); }
-
@ademmler said in Qprocess: how to debug the full command send/used to start the process?:
I have doubts that Process creates the proper command in my case.
What the debug output from @Pl45m4 show you is exactly what the process gets.
-
Ok - In the terminal - from qDebug() I see everything is fine.
I added as @Pl45m4 have said.
qDebug() << myProcess->program() << " " << myProcess->arguments();Which brings this as a result:
"pdfraster64" ("-overprint", "-overprintMode 3", "-antialias yes", "-aavector yes", "-devn", "-plateInfo", "-dpi 50", "-devnstatus /Users/ademmler/Desktop/test4C.pdf.devn", "/Users/ademmler/Desktop/test4C.pdf", "/Users/ademmler/Desktop/test4C.pdf.tiff")But the command (aka rip) is not started at all ...
And there is nothing on stdout or stderr ...Again -how can I debug this than?
QString program = "pdfraster64"; QStringList arguments; arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile); myProcess = new QProcess(this); myProcess->start(program, arguments); qDebug() << myProcess->program() << " " << myProcess->arguments();
-
@ademmler said in Qprocess: how to debug the full command send/used to start the process?:
arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:
<< "-aavector" << "yes"
-
@SGaist thx for pointing this out. That was the missing part.
Hence "all kind of spaces" are handled by Process - right?What is your recommendation how to create such long/complex list of arguments?
Can I write it like this - or is there a better way of doing?arguments << "-overprint" << "-overprintMode 3"
<< "-antialias" << yes"
<< "-aavector yes"
<< "-devn" << "-plateInfo"
<< "-dpi " + QString::number(ripResolutionLow)
<< "-devnstatus " + rep.toNativeSeparators(report)
<< in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile); -
If I have long list of that kind of stuff, I put each entry on its own line.
-
@SGaist thx - You mean - as I wrote it above.
There is comandline tools which syntax uses "="
like this: executable -option1 -option2=3
or even this: executable -option1 -option2 = 3This would lead into: arguments << "-option1" << "-option2=" << "3";
Or into arguments << "-option1" << "-option2" << "=" << "3"; -
I am so sorry - I marked the wrong answer as the correct one.
Does this Forum allow me to change this? I don't find the button for this ...I Marked @SGaist answer as solution, because this made everything work.
I think it ia so important to understand that options and values need to be in separate quotes!
Bevor I could never get a Process running ... maybe a good note for the documentation. -
You can mark your thread as unsolved (done) and select a new answer.