PDA

View Full Version : QProcess and mysql < backup.sql



gboelter
21st August 2009, 09:14
How can I get this working:



QString str = "mysql -uUser -pPassword -h172.16.1.110 < backup.sql";
myProcess->start( str );


I've tried it with a string and with a list, but it's both not working. I guess, my problem is the " < " as a part of my string. If the "<" is included, then mysql shows me the same like with "mysql --help", but no error message or something usefull else.

The same string at the commandline works well.

I'm using Qt 4.5.2 under Fedora 9.

Thanks in advance.

wagmare
21st August 2009, 09:20
as you are using Qt4.x version
QProcess::start() usally defined as

void QProcess::start ( const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite )


QString proc = "mysql";
QStringList args;

args << " -uUser" <<"-pPassword" << "h172.16.1.110" << "<" << "ba...sql" ;

myprocess->start(proc, args);

gboelter
21st August 2009, 11:19
QString proc = "mysql";
QStringList args;
args << " -uUser" <<"-pPassword" << "h172.16.1.110" << "<" << "ba...sql" ;
myprocess->start(proc, args);


Thanks for your reply, but I have tried it before already in this way. Same result. Here is a part of the output I got:


"mysql Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i386) using readline 5.1
Copyright (C) 2000-2008 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
-A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get
table and field completion. This gives a quicker start of
mysql and disables rehashing on reconnect. WARNING:
options deprecated; use --disable-auto-rehash instead.
-B, --batch Don't use history file. Disable interactive behavior.
(Enables --silent)
--character-sets-dir=name


I can make a backup with:


QString backup = "mysqldump --database " + db
+ " --user=" + dbUser
+ " --password=" + dbPassword
+ " --host=" + dbHost
+ " --log-error backup.log"
+ " --verbose --opt"
+ " --result-file " + fileName;
myProcess->start( backup );


This works fine for me, but at the moment I add "<" to a commandline, then it's not working anymore.

yogeshgokul
21st August 2009, 11:24
This works fine for me, but at the moment I add "<" to a commandline, then it's not working anymore.
Whats this for pipe lining or something ?

gboelter
21st August 2009, 11:29
Whats this for pipe lining or something ?

I don't know. It's a part of a standard command for mysql.

On a command line "mysql -uMyUser -pMyPassword < backup.sql" works fine for me, but the same line with QProgress don't work.

yogeshgokul
21st August 2009, 11:39
Read this (http://www.devshed.com/c/a/MySQL/Backing-up-and-restoring-your-MySQL-Database/).
Please try to use reverse sign.
">" instead of "<".

If it works ! fine.
Otherwise I suggest, do not use any one. Because this sign is just passing the backup file name to MySql command. And your code is working so you don't need any sign.

lyuts
21st August 2009, 14:10
1) Are you sure myProcess knows where backup.sql is located?
2) What if you pass "-e backup.sql" instead of passing backup.sql through redirection?

gboelter
22nd August 2009, 07:09
1) Are you sure myProcess knows where backup.sql is located?
2) What if you pass "-e backup.sql" instead of passing backup.sql through redirection?

Thank you guys,

the problem is really the "<" sign, no idea why ... :confused:

With "-e backup.sql" it don't work too, so I have changed the way to do backup & restore to this now:



myProcess->start( curDir+"/restore", QStringList() << db << dbUser << dbPassword << dbHost << fileName );

where 'restore' is a simple batch file.

I guess, it's even the better approach because it's easy to change, if somebody has a different SQL-database.

Thanks again and have a nice day.

lyuts
22nd August 2009, 12:47
What if you specify the full path to backup.sql?

gboelter
23rd August 2009, 04:22
What if you specify the full path to backup.sql?

The same, not working ...

And if I make a mistake in writing, 'back-up.sql' for example, then QProcess tells me 'file not found'. That means for me, that the file can not be the problem.

kkk777kkk
15th February 2010, 10:52
yes the sign < and > don't work if you use qprocess
but i find how to use this:

void QProcess::setStandardInputFile ( const QString & fileName )
void QProcess::setStandardOutputFile ( const QString & fileName, OpenMode mode = Truncate )

this works fine :p

Lesiok
15th February 2010, 11:30
"< backup.sql" this is a parameter for Command Interpreter not for mysql. It redirects stdio to file backup.sql. mysql has nothing to this.

endof
10th July 2011, 18:15
How can I get this working:



QString str = "mysql -uUser -pPassword -h172.16.1.110 < backup.sql";
myProcess->start( str );


I've tried it with a string and with a list, but it's both not working. I guess, my problem is the " < " as a part of my string. If the "<" is included, then mysql shows me the same like with "mysql --help", but no error message or something usefull else.

The same string at the commandline works well.

I'm using Qt 4.5.2 under Fedora 9.

Thanks in advance.


use bash -c " " bash command


QString str = "bash -c \"mysql -uUser -pPassword -h172.16.1.110 < backup.sql\" ";
myProcess->start( str );