Sign in to follow this  
Followers 0
b0br0ff

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

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
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

1 person likes this

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0