QProcess not working.
-
I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:
Log Name: Application Source: MariaDB Date: 26/07/2021 08:18:28 Event ID: 100 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: LHR1-EUD-L20381 Description: Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="MariaDB" /> <EventID Qualifiers="49152">100</EventID> <Version>0</Version> <Level>3</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" /> <EventRecordID>149973</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>LHR1-EUD-L20381</Computer> <Security /> </System> <EventData> <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) </Data> </EventData> </Event>
My code:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << (QString(">") + strFilename); strApp = ""; foreach( QString strArg, slstArguments ) { if ( strApp.isEmpty() != true ) { strApp += " "; } strApp += strArg; } qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
In the console I am seeing:
PID: 4968, newState: QProcess::ProcessState(NotRunning)
The actual command line is:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
If I copy the above and paste into a command prompt, it works. But not from the application.
-
@SPlatten said in QProcess not working.:
@JonB , where are you getting process and exec from?
It's an example of
QProcess::exec()
. Actually that'sstatic
. Exactly the same principle if you want to usepobjProcess->start();
. It's the argument passing I'm trying to tell you about.if I copy the command line and arguments to a command prompt it works,
Yes, as I said this will (only) work from
cmd
.<< QString(">") << strFilename;
As I said, this won't work for
mysqldump
run as an executable. It will only work viacmd /c ...
. Up to you whether you believe me :) -
I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:
Log Name: Application Source: MariaDB Date: 26/07/2021 08:18:28 Event ID: 100 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: LHR1-EUD-L20381 Description: Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="MariaDB" /> <EventID Qualifiers="49152">100</EventID> <Version>0</Version> <Level>3</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" /> <EventRecordID>149973</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>LHR1-EUD-L20381</Computer> <Security /> </System> <EventData> <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) </Data> </EventData> </Event>
My code:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << (QString(">") + strFilename); strApp = ""; foreach( QString strArg, slstArguments ) { if ( strApp.isEmpty() != true ) { strApp += " "; } strApp += strArg; } qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
In the console I am seeing:
PID: 4968, newState: QProcess::ProcessState(NotRunning)
The actual command line is:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
If I copy the above and paste into a command prompt, it works. But not from the application.
@SPlatten said in QProcess not working.:
pobjProcess->setArguments(slstArguments);
pobjProcess->setProgram(strApp);hi,
you do realise, that at this point strApp also has the arguments appended to it?
it should be only the program, and the arguments as string list separately
-
I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:
Log Name: Application Source: MariaDB Date: 26/07/2021 08:18:28 Event ID: 100 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: LHR1-EUD-L20381 Description: Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="MariaDB" /> <EventID Qualifiers="49152">100</EventID> <Version>0</Version> <Level>3</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" /> <EventRecordID>149973</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>LHR1-EUD-L20381</Computer> <Security /> </System> <EventData> <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) </Data> </EventData> </Event>
My code:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << (QString(">") + strFilename); strApp = ""; foreach( QString strArg, slstArguments ) { if ( strApp.isEmpty() != true ) { strApp += " "; } strApp += strArg; } qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
In the console I am seeing:
PID: 4968, newState: QProcess::ProcessState(NotRunning)
The actual command line is:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
If I copy the above and paste into a command prompt, it works. But not from the application.
@SPlatten said in QProcess not working.:
If I copy the above and paste into a command prompt, it works. But not from the application.
I have 2 remarks:
- I am always surprise about your coding style, it seems that you always have to overload every Qt base class. If I have right understood your code,
process
is a sub-class ofQProcess
. - It looks to me as the application is also part of the arguments, why?
- I am always surprise about your coding style, it seems that you always have to overload every Qt base class. If I have right understood your code,
-
I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:
Log Name: Application Source: MariaDB Date: 26/07/2021 08:18:28 Event ID: 100 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: LHR1-EUD-L20381 Description: Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="MariaDB" /> <EventID Qualifiers="49152">100</EventID> <Version>0</Version> <Level>3</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" /> <EventRecordID>149973</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>LHR1-EUD-L20381</Computer> <Security /> </System> <EventData> <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) </Data> </EventData> </Event>
My code:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << (QString(">") + strFilename); strApp = ""; foreach( QString strArg, slstArguments ) { if ( strApp.isEmpty() != true ) { strApp += " "; } strApp += strArg; } qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
In the console I am seeing:
PID: 4968, newState: QProcess::ProcessState(NotRunning)
The actual command line is:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
If I copy the above and paste into a command prompt, it works. But not from the application.
@SPlatten Why don't you connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred and check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns?
I would split "<< (QString(">") + strFilename);" into two parameters.
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr )
Why do you check pobjProcess pointer after alloocating memory? This is useless as in case of out of memory your app will be terminated anyway.
-
@SPlatten Why don't you connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred and check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns?
I would split "<< (QString(">") + strFilename);" into two parameters.
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr )
Why do you check pobjProcess pointer after alloocating memory? This is useless as in case of out of memory your app will be terminated anyway.
@jsulm said in QProcess not working.:
This is useless as in case of out of memory your app will be terminated anyway.
not necessarily
I see 2 cases where one would do such a thing- if the OP compiles with
-fno-exceptions
than it will be indeed a null pointer returned instead of an exception - If the OP overloaded new and explicitly returns nullptr if some condition is met/not met
- if the OP compiles with
-
I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:
Log Name: Application Source: MariaDB Date: 26/07/2021 08:18:28 Event ID: 100 Task Category: None Level: Warning Keywords: Classic User: N/A Computer: LHR1-EUD-L20381 Description: Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="MariaDB" /> <EventID Qualifiers="49152">100</EventID> <Version>0</Version> <Level>3</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" /> <EventRecordID>149973</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>LHR1-EUD-L20381</Computer> <Security /> </System> <EventData> <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets) </Data> </EventData> </Event>
My code:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << (QString(">") + strFilename); strApp = ""; foreach( QString strArg, slstArguments ) { if ( strApp.isEmpty() != true ) { strApp += " "; } strApp += strArg; } qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
In the console I am seeing:
PID: 4968, newState: QProcess::ProcessState(NotRunning)
The actual command line is:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
If I copy the above and paste into a command prompt, it works. But not from the application.
@SPlatten said in QProcess not working.:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
You have chosen to use a DOS/Windows
>
redirection symbol on your command line. This cannot be executed directly, i.e. executingmysqldump
and passing>...
to it.If you do it this way you must execute via
QStringList args { "/c", "\"C:\\Program Files (x86)\\MariaDB 10.5\\bin\\mysqldump\" --host=localhost --user=trainer --password=CobhamAC training >C:\\Users\\simon.platten\\Documents\\TrainerS1D5.sql" }; process->exec("cmd", args);
Or handle the output redirection yourself in the caller, or via an "output-to" argument to
mysqldump
if it supports that. -
@SPlatten said in QProcess not working.:
pobjProcess->setArguments(slstArguments);
pobjProcess->setProgram(strApp);hi,
you do realise, that at this point strApp also has the arguments appended to it?
it should be only the program, and the arguments as string list separately
-
@SPlatten said in QProcess not working.:
"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
You have chosen to use a DOS/Windows
>
redirection symbol on your command line. This cannot be executed directly, i.e. executingmysqldump
and passing>...
to it.If you do it this way you must execute via
QStringList args { "/c", "\"C:\\Program Files (x86)\\MariaDB 10.5\\bin\\mysqldump\" --host=localhost --user=trainer --password=CobhamAC training >C:\\Users\\simon.platten\\Documents\\TrainerS1D5.sql" }; process->exec("cmd", args);
Or handle the output redirection yourself in the caller, or via an "output-to" argument to
mysqldump
if it supports that. -
I've changed the code back to:
process* pobjProcess(new process(this)); if ( pobjProcess != nullptr ) { QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << QString(">") << strFilename; qdbg() << slstArguments; qdbg() << strApp; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->setArguments(slstArguments); pobjProcess->setProgram(strApp); pobjProcess->start(); QObject::connect(pobjProcess, &QProcess::errorOccurred, [this](QProcess::ProcessError err) { qdbg() << "Error: " << err; } ); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qdbg() << "PID: " << cint64PID << ", newState: " << newState; } ); }
Still doesn't work and I'm not seeing anything errorOccurred
-
@J-Hilk , yes, it didn't originally, I add those later just to see if it made any difference.
@SPlatten said in QProcess not working.:
yes, it didn't originally, I add those later just to see if it made any difference.
I don't really know what is the purpose of this, I guess you have to get SQL statements from you DB.
My way to achieve it would be:
- start
mysqldump
withQProcess
- wait until
QProcess
/mysqldump
finished - read
QProcess
output (cf.QProcess::readAll()
) ==> no need of redirection at all
And last remark:
you have to do connection before starting process, to be sure not to loose state changes ;) - start
-
@SPlatten said in QProcess not working.:
yes, it didn't originally, I add those later just to see if it made any difference.
I don't really know what is the purpose of this, I guess you have to get SQL statements from you DB.
My way to achieve it would be:
- start
mysqldump
withQProcess
- wait until
QProcess
/mysqldump
finished - read
QProcess
output (cf.QProcess::readAll()
) ==> no need of redirection at all
And last remark:
you have to do connection before starting process, to be sure not to loose state changes ;)@KroMignon I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.
- start
-
@SPlatten said in QProcess not working.:
@JonB , where are you getting process and exec from?
It's an example of
QProcess::exec()
. Actually that'sstatic
. Exactly the same principle if you want to usepobjProcess->start();
. It's the argument passing I'm trying to tell you about.if I copy the command line and arguments to a command prompt it works,
Yes, as I said this will (only) work from
cmd
.<< QString(">") << strFilename;
As I said, this won't work for
mysqldump
run as an executable. It will only work viacmd /c ...
. Up to you whether you believe me :) -
@KroMignon I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.
@SPlatten said in QProcess not working.:
I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.
With QProcess, you don't start the process from a shell / command prompt, that is the difference here.
Try this:auto proc = new QProcess; QObject::connect(proc, &QProcess::stateChanged, [proc](QProcess::ProcessState newState) { qDebug() << "new state is " << newState; if(newState == QProcess::NotRunning) { QString output(proc->readAll()); qDebug() << "Output is" << output; proc->delateLater(); } }); proc->setWorkingDirectory(strDBinstFolder); proc->start(strApp,slstArguments );
EDIT: do NOT add redirection in slstArguments !!!
EDIT BIS:
QStringList slstArguments; slstArguments << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase());
==> I suppose that DataSets::mscszOptionHost contains
--host=
-
@SPlatten said in QProcess not working.:
@JonB , where are you getting process and exec from?
It's an example of
QProcess::exec()
. Actually that'sstatic
. Exactly the same principle if you want to usepobjProcess->start();
. It's the argument passing I'm trying to tell you about.if I copy the command line and arguments to a command prompt it works,
Yes, as I said this will (only) work from
cmd
.<< QString(">") << strFilename;
As I said, this won't work for
mysqldump
run as an executable. It will only work viacmd /c ...
. Up to you whether you believe me :) -
@SPlatten
int QProcess::execute(const QString &program, const QStringList &arguments) [static]. So it'sexecute
. It was introduced into some Qt. I don't know about 5.9.2.As I said, forget I ever wrote
exec
orexecute
. The same argument processing applies toQProcess::start
. You keep passing>
argument, and I've explained this won't work. -
@SPlatten said in QProcess not working.:
I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.
With QProcess, you don't start the process from a shell / command prompt, that is the difference here.
Try this:auto proc = new QProcess; QObject::connect(proc, &QProcess::stateChanged, [proc](QProcess::ProcessState newState) { qDebug() << "new state is " << newState; if(newState == QProcess::NotRunning) { QString output(proc->readAll()); qDebug() << "Output is" << output; proc->delateLater(); } }); proc->setWorkingDirectory(strDBinstFolder); proc->start(strApp,slstArguments );
EDIT: do NOT add redirection in slstArguments !!!
EDIT BIS:
QStringList slstArguments; slstArguments << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase());
==> I suppose that DataSets::mscszOptionHost contains
--host=
@KroMignon , I've tried this:
QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << QString(">") << strFilename; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->start(strApp, slstArguments); QObject::connect(pobjProcess, &QProcess::errorOccurred, [this](QProcess::ProcessError err) { qDebug() << "Error: " << err; }); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qDebug() << "PID: " << cint64PID << ", newState: " << newState; });
-
@KroMignon , I've tried this:
QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << QString(">") << strFilename; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->start(strApp, slstArguments); QObject::connect(pobjProcess, &QProcess::errorOccurred, [this](QProcess::ProcessError err) { qDebug() << "Error: " << err; }); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qDebug() << "PID: " << cint64PID << ", newState: " << newState; });
@SPlatten Did you notice "EDIT: do NOT add redirection in slstArguments !!!" in @KroMignon post?
Why do you need redirection to a file if you can simply read the stdout from the process as @KroMignon already suggested? -
@KroMignon , I've tried this:
QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << ("\"" + strDBinstFolder + strApp + "\"") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()) << QString(">") << strFilename; pobjProcess->setWorkingDirectory(strDBinstFolder); pobjProcess->start(strApp, slstArguments); QObject::connect(pobjProcess, &QProcess::errorOccurred, [this](QProcess::ProcessError err) { qDebug() << "Error: " << err; }); QObject::connect(pobjProcess, &QProcess::stateChanged, [pobjProcess](QProcess::ProcessState newState) { const qint64 cint64PID(pobjProcess->processId()); if ( newState == QProcess::NotRunning ) { } else if ( newState == QProcess::Running && cint64PID > 0 ) { } qDebug() << "PID: " << cint64PID << ", newState: " << newState; });
-
@SPlatten Did you notice "EDIT: do NOT add redirection in slstArguments !!!" in @KroMignon post?
Why do you need redirection to a file if you can simply read the stdout from the process as @KroMignon already suggested? -
@jsulm The purpose of this is to provide an export / backup facility of the database to an SQL file.