Can't launch simple command with qprocess
Unsolved
General and Desktop
-
Hi,
I'm trying to launch a console command via qprocess but execute always return -2 (process can't start i mean). My purpose is more complicated but the simple code below do nothing:
QProcess gitProcess; gitProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); gitProcess.setWorkingDirectory(QString::fromLatin1(a_args.workingDirectory)); int iRet = gitProcess.execute("mkdir test");
I don't understand what I do wrong.
Thanks.
(sorry for my english) -
first of, you need to realise QProcess is not a terminal/shell/commandprompt .
but you can launch one with it and have that one execute your mkdir command:
I assume Windows(?)
QProcess Process; QObject::connect(&Process, &QProcess::errorOccurred, &app, [](QProcess::ProcessError error)->void{qDebug() << error;}); Process.start("cmd.exe", QStringList() << "/C" <<"mkdir"<< "test");
-
Hi
mkdir is not an .exe file but a build-in command and hence you can't just start it and has to start it via
cmd.exe as J-Hilk shows. -
Hi,
Or more cross-platform: QDir::mkdir.