0

I am trying to get the "process list" from mysql and output it into a file for logging purposes. here is the VBScript code:

 Const ForReading = 1, ForWriting = 2, ForAppending = 8
 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
 Dim fso, ts, fileObj, TextLine

 Set fso = CreateObject("Scripting.FileSystemObject")
 FileName = "mysqlprocess.log"

 If Not(fso.FileExists(FileName)) Then
    'File does not exist'
fso.CreateTextFile FileName
 End If

 'Obtain a file object for the file'
  Set fileObj = fso.GetFile(FileName)

 ' Open a text stream for output.
 Set ts = fileObj.OpenAsTextStream(ForAppending, TristateUseDefault)

 ' Write to the text stream.
 ts.WriteLine Date & " - " & Time
 ts.WriteLine

 Set objShell = WScript.CreateObject("WScript.Shell")
 'comspec = objShell.ExpandEnvironmentStrings("%comspec%")'

 Set objExec = objShell.Exec("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql -u root -ppassword mydatabase -t -e 'show processlist;'")
 Do
     line = objExec.StdOut.ReadLine()
     strOutput = strOutput & line & vbcrlf
 Loop While Not objExec.Stdout.atEndOfStream

 ts.WriteLine strOutput

 ts.WriteLine "=============================================="
 ts.Close

And here is what is written into the mysqlprocesslist.log file:

5/06/2013 - 1:08:58 PM

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql Ver 14.14 Distrib 5.5.15, for Win64 (x86) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Usage: C:\Program Files\MySQL\MySQL Server 5.5\bin\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. (Defaults to on; use --skip-auto-rehash to disable.) -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. [.............]

So this is working as if it was not reading out the arguments. I tried to change the Exec line to include spaces, but this didn't work either:

 Set objExec = objShell.Exec("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" & " -u root -ppassword mydatabase -t -e 'show processlist;'")

Is there anything I am doing wrong here?

1 Answer 1

1

I got it right, the problem was with the single quote syntax:

Set objExec = objShell.Exec("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql -u root -ppassword mydatabase -t -e 'show processlist;'")

The correct one is:

Set objExec = objShell.Exec("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql -u root -ppassword mydatabase -t -e ""show processlist;""")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.