Jump to content

MySQL: Problem executing SQL script and dump results to TXT file


b0br0ff
 Share

Recommended Posts

Hi, I am trying to perform very easy stuff with AutoIT, i.e. to execute simple SQL query on the MySQL server and save results to the text file. Code sample:

Local $sCmd = @ComSpec & " /c """ & $MySqlPath &"bin""mysql.exe"

$sCmd = $sCmd & " --host=" & $host

$sCmd = $sCmd & " --user=" & $user

$sCmd = $sCmd & " --password=" & $passwd

$sCmd = $sCmd & " --port=" & $port

$sCmd = $sCmd & " < C:tempsql1.txt"

$sCmd = $sCmd & " > C:temp2.txt"

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sCmd = ' & $sCmd & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

;MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$sCmd' & @lf & @lf & 'Return:' & @lf & $sCmd) ;### Debug MSGBOX

Local $val = RunWait($sCmd, "", @SW_MAXIMIZE)

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $val = ' & $val & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

Problem is that output file is always created empty, however when I execute same command in CMD everything is ok.

C:Usersuser>"C:Program FilesMySQLMySQL Server 5.5bin"mysql.exe --host=localhost --user=root --password= --port=3306 < C:tempsql1.txt > C:temp2.txt

Thank You in advance!

Edited by b0br0ff
Link to comment
Share on other sites

RunWait will not give you the text output on the console by the command you run with it. It will only give you the return code, if there is one.

Take a look at It was very helpful for me.

Link to comment
Share on other sites

b0br0ff,

When run from the command line you are piping the output to a file. When run from the script you are doing nothing with the output, as WillChan alluded to. See STDOUTREAD in the help file, if you want to stay with your current method.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...