Results 1 to 13 of 13

Thread: QProcess and mysql < backup.sql

  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QProcess and mysql < backup.sql

    How can I get this working:

    Qt Code:
    1. QString str = "mysql -uUser -pPassword -h172.16.1.110 < backup.sql";
    2. myProcess->start( str );
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    as you are using Qt4.x version
    QProcess::start() usally defined as

    void QProcess::start ( const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite )
    Qt Code:
    1. QString proc = "mysql";
    2.  
    3. args << " -uUser" <<"-pPassword" << "h172.16.1.110" << "<" << "ba...sql" ;
    4.  
    5. myprocess->start(proc, args);
    To copy to clipboard, switch view to plain text mode 
    Last edited by wagmare; 21st August 2009 at 09:25. Reason: edited args
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by wagmare View Post
    Qt Code:
    1. QString proc = "mysql";
    2. args << " -uUser" <<"-pPassword" << "h172.16.1.110" << "<" << "ba...sql" ;
    3. myprocess->start(proc, args);
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. QString backup = "mysqldump --database " + db
    2. + " --user=" + dbUser
    3. + " --password=" + dbPassword
    4. + " --host=" + dbHost
    5. + " --log-error backup.log"
    6. + " --verbose --opt"
    7. + " --result-file " + fileName;
    8. myProcess->start( backup );
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by gboelter View Post
    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 ?

  5. #5
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by yogeshgokul View Post
    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.

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Read this.
    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.
    Last edited by yogeshgokul; 21st August 2009 at 11:53.

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and mysql < backup.sql

    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?
    I'm a rebel in the S.D.G.

  8. #8
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by lyuts View Post
    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 ...

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

    Qt Code:
    1. myProcess->start( curDir+"/restore", QStringList() << db << dbUser << dbPassword << dbHost << fileName );
    To copy to clipboard, switch view to plain text mode 

    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.

  9. #9
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and mysql < backup.sql

    What if you specify the full path to backup.sql?
    I'm a rebel in the S.D.G.

  10. The following user says thank you to lyuts for this useful post:

    gboelter (23rd August 2009)

  11. #10
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by lyuts View Post
    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.

  12. #11
    Join Date
    Dec 2009
    Location
    Kiev, Ukraine
    Posts
    16
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QProcess and mysql < backup.sql

    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
    Last edited by kkk777kkk; 15th February 2010 at 10:56.

  13. #12
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and mysql < backup.sql

    "< backup.sql" this is a parameter for Command Interpreter not for mysql. It redirects stdio to file backup.sql. mysql has nothing to this.

  14. #13
    Join Date
    Jun 2011
    Location
    TURKEY
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess and mysql < backup.sql

    Quote Originally Posted by gboelter View Post
    How can I get this working:

    Qt Code:
    1. QString str = "mysql -uUser -pPassword -h172.16.1.110 < backup.sql";
    2. myProcess->start( str );
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. QString str = "bash -c \"mysql -uUser -pPassword -h172.16.1.110 < backup.sql\" ";
    2. myProcess->start( str );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QProcess, plink, mysql
    By tpf80 in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2008, 02:28
  2. QProcess' writeToStdin
    By Shlainn in forum Qt Programming
    Replies: 2
    Last Post: 19th September 2006, 13:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.