2
votes

I am a beginner in VBScript.

I need execute in VBScript this command line:

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld --defaults-file=C:\Program Files\MySQL\MySQL Server 5.5\my.ini MySQL

I googled it & got to know that we can run VBScript from command line by executing below command and I have tried this:

Set oShell = Wscript.CreateObject("WScript.Shell")          
oShell.run "cmd /k ""C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld --defaults-file=C:\Program Files\MySQL\MySQL Server 5.5\my.ini MySQL", 1, True 

But the script is stopped because in the path of the file my.ini there are some folder with space in the name, that is Program Files and MySQL Server 5.5

How to do resolve this?

2
You need to double the quotes to escape them, try this oShell.run "cmd /k ""C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld --defaults-file=C:\Program Files\MySQL\MySQL Server 5.5\my.ini MySQL""", 1, True.user692942
You should probably look at the usage information presented when entering cscript /? at the Command Prompt too!Compo

2 Answers

1
votes

You can save the Filepath in a Variable and run it.

Set oShell = Wscript.CreateObject("WScript.Shell") 
Dim path = "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld --defaults-file=C:\Program Files\MySQL\MySQL Server 5.5\my.ini MySQL"         
oShell.run "cmd /k " path , 1, True

Good Luck

Jonas

1
votes

First : To make life easier just use this function to double quotes your strings and debug your command with wscript.echo or a MsgBox before executing it !

SQL_CMD = "cmd /k "& DblQuote("C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld.exe") &_
"--defaults-file="& DblQuote("C:\Program Files\MySQL\MySQL Server 5.5\my.ini") & " MySQL"
wscript.echo SQL_CMD
'--------------------------------------
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'--------------------------------------