command prompt command execution in Qt
-
How command prompt command execution in Qt application
like in case of - gedit my.txt in command prompt my.txt file be open to edit
in case of - mkdir Qt in command prompt i have to execute this command and want to create folderThank you in Advance.
-
How command prompt command execution in Qt application
like in case of - gedit my.txt in command prompt my.txt file be open to edit
in case of - mkdir Qt in command prompt i have to execute this command and want to create folderThank you in Advance.
Any one here ?
-
How command prompt command execution in Qt application
like in case of - gedit my.txt in command prompt my.txt file be open to edit
in case of - mkdir Qt in command prompt i have to execute this command and want to create folderThank you in Advance.
QProcess::execute("gedit my.txt")
QProcess::execute("mkdir folder")
In practice you should probably use the http://doc.qt.io/qt-5/qprocess.html#execute overload to pass the argument(s) as a
QStringList
.P.S.
To create a folder, don't actually use a sub-process ofmkdir
, use the in-built Qt function for creating a directory. -
Any one here ?
@Pranit-Patil said in command prompt command execution in Qt:
Any one here ?
You posted that 9 minutes after your original query. Do you pay for my support, or anyone else's, within 10 minutes? :( Or do you just think it's my/our duty? In which case I'll leave it to others for you from now on...
-
QProcess::execute("gedit my.txt")
QProcess::execute("mkdir folder")
In practice you should probably use the http://doc.qt.io/qt-5/qprocess.html#execute overload to pass the argument(s) as a
QStringList
.P.S.
To create a folder, don't actually use a sub-process ofmkdir
, use the in-built Qt function for creating a directory.@JonB
i m doing simply like this but not getting o/pQProcess process;
QString exePath = "C:/Windows/ystem32/cmd.exe";
process.start(exePath);
process.execute("cmd.exe"); -
@JonB
i m doing simply like this but not getting o/pQProcess process;
QString exePath = "C:/Windows/ystem32/cmd.exe";
process.start(exePath);
process.execute("cmd.exe");@Pranit-Patil
I gave you the lines to type for your question. If you choose to do something quite different and wrong, that's up to you. Perhaps others will sort you out. -
@Pranit-Patil
I gave you the lines to type for your question. If you choose to do something quite different and wrong, that's up to you. Perhaps others will sort you out.@JonB sorry for that
i tried your examples
QProcess::execute("gedit my.txt");
QProcess::execute("mkdir Test");but not getting any error or any output.
-
@JonB sorry for that
i tried your examples
QProcess::execute("gedit my.txt");
QProcess::execute("mkdir Test");but not getting any error or any output.
Neither command should produce any error or output. Unless you don't even have
gedit
.... And if you're Windows (your question does not even mention the OS), you may needQProcess::execute("cmd /c mkdir Test");
. -
Neither command should produce any error or output. Unless you don't even have
gedit
.... And if you're Windows (your question does not even mention the OS), you may needQProcess::execute("cmd /c mkdir Test");
.@JonB Im Developing application in Qt creator 4.6.0 on windows 7 -32bit
#include <QProcess>
#include <QDir>
void Command::on_pushButton_clicked()
{
QProcess process;
QString exePath1 = "D:/Phoenix";
process.start(exePath1);
process.execute("cmd /c mkdir test");
}
not getting any output. -
@JonB Im Developing application in Qt creator 4.6.0 on windows 7 -32bit
#include <QProcess>
#include <QDir>
void Command::on_pushButton_clicked()
{
QProcess process;
QString exePath1 = "D:/Phoenix";
process.start(exePath1);
process.execute("cmd /c mkdir test");
}
not getting any output.@Pranit-Patil "not getting any output." - what "output" do you expect?
Why do you start new process to create a directory? You can do this way faster and easier with Qt (http://doc.qt.io/qt-5/qdir.html#mkdir)
Also this does not make any sense:QProcess process; QString exePath1 = "D:/Phoenix"; process.start(exePath1); process.execute("cmd /c mkdir test");
You can't start a directory as it is not an executable. There is no need to use both start() AND execute().
Did you actually read QProcess documentation?!
It has a nice example:QString program = "./path/to/Qt/examples/widgets/analogclock"; QStringList arguments; arguments << "-style" << "fusion"; QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments);
-
@Pranit-Patil "not getting any output." - what "output" do you expect?
Why do you start new process to create a directory? You can do this way faster and easier with Qt (http://doc.qt.io/qt-5/qdir.html#mkdir)
Also this does not make any sense:QProcess process; QString exePath1 = "D:/Phoenix"; process.start(exePath1); process.execute("cmd /c mkdir test");
You can't start a directory as it is not an executable. There is no need to use both start() AND execute().
Did you actually read QProcess documentation?!
It has a nice example:QString program = "./path/to/Qt/examples/widgets/analogclock"; QStringList arguments; arguments << "-style" << "fusion"; QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments);
@jsulm
I already pointed all this stuff to OP above.
Additionally, I also deliberately usedQProcess::execute()
in my examples for him to keep it down to one liners. Each time he has also added an additionalQProcess::start()
. I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :) -
@jsulm
I already pointed all this stuff to OP above.
Additionally, I also deliberately usedQProcess::execute()
in my examples for him to keep it down to one liners. Each time he has also added an additionalQProcess::start()
. I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :)@JonB
Thank you for your reply
Sorry sir i didn't understand what your saying ..?aim - create folder in my system using commands of cmd prompt in any location through QT application.
Im new in Qt i don't have more knowledge on it plz suggest
-
@jsulm
I already pointed all this stuff to OP above.
Additionally, I also deliberately usedQProcess::execute()
in my examples for him to keep it down to one liners. Each time he has also added an additionalQProcess::start()
. I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :)