CMD write/read issue
-
Hi! I want to write/read
CMD
data fromGUI
application.For example:
QProcess *process = new QProcess(); connect(process , &QProcess::started, [this]() { qDebug() << "Started!"; }); connect(process, &QProcess::readyRead, [this]() { QTextStream outputStream(process->readAllStandardOutput()); outputStream.setCodec("IBM 866"); ui->textBrowser->append(outputStream.readAll()); }); connect(process , &QProcess::readyReadStandardOutput, [this]() { QTextStream outputStream(process->readAllStandardOutput()); outputStream.setCodec("IBM 866"); ui->textBrowser->append(outputStream.readAll()); }); connect(process, &QProcess::readyReadStandardError, [this]() { QTextStream errorStream(process->readAllStandardError()); errorStream.setCodec("IBM 866"); ui->textBrowser->append(errorStream.readAll()); }); connect(process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), [this](int exitCode, QProcess::ExitStatus exitStatus) { ui->textBrowser->append(QString::number(exitCode) + " " + QString::number(exitStatus)); process->deleteLater(); }); process->start("cmd.exe", "/K cd %USERPROFILE%");
I write to
CMD
:process->write(QString("cd ..").toUtf8());
I checked that it writes:
"cd .." 5 bytes
but nothing is in output:
Any ideas? Thanks in advance.
-
Hi
But the cd command do not give any output ?
so what do you expect that it should return ? -
@Cobra91151
Hi
I see your point, but i am not sure it works that way.
The change in the prompt is not directly from the cd command.
it does not return the new path or anything so i dont think there is anything to read.
needed \n -
You're sending input as if you typed it in the command line window, therefore you need to pass "enter" to execute the statement i.e.
cd ..\n
. -
He can then read the changed prompt?
-
@Chris-Kawa said in CMD write/read issue:
cd ..\n
Yes, I know that. I tried it but the output is the same.
I will create the small example to reproduce it.
-
@mrjj said:
He can then read the changed prompt?
Yes, it will be available for reading in those readyRead... signals.
So how to write to stdin appropriate command using QProcess?
Just as you would with
cd
i.e.y\n
. But first check if that tool doesn't have some sort of switch to automatically accept prompts. Some utilities have a switch line/quiet
,/silent
,/autoconfirm
,/unattended
etc. Maybe that one has too.Yes, I know that. I tried it but the output is the same.
I checked. It works. You must have something different in your actual code than shown here then.
-
Yes, you are right,
dism
has/NoRestart
parameter (Suppresses automatic reboots and reboot prompts.
). As for the current write issue, I am still working on it. -
Ok. I found the problem:
process->closeReadChannel(QProcess::StandardOutput);
So, it closes the read channel and that's why can't output anything. My mistake. I am working on website/app dev simultaneously :) The issue is resolved.