I've written a script that dumps a MySQL db to another MySQL db. The core of the script is this --->


'Begin Code

strCommand = "C:\mysql\bin\mysqldump --opt -u " & strUser & " -p""" & strPass & """ " & strSouceDB & " | C:\mysql\bin\mysql -C -u " & strUser & " -p""" & strPass & """ -h Intranet " & strDestDB
Set WshShell = CreateObject("WScript.Shell")
Set objExec = WshShell.Exec(strCommand)

'End Code


yeah... I realize the command line is ugly.

Here's the ouput from stdERR:

C:\mysql\bin\mysqldump: Got error: 1064: You have an error in your SQL syntax
near '| READ /*!32311 LOCAL */,C:\mysql\bin\mysql READ /*!32311 LOCAL */,- C READ /*!32' at line 1



I can do this ---> "WScript.Echo strCommand" and output the command line, then paste it in a
cmd window and it runs flawlessly. So the command line is being built correctly... or so I think.
So my guess is that WScript.Exec( ) is dying somehow because of strCommand.
I've tried the Chr(34) method instead of escaping the quotes around strPass (yes
they have to be there cause the password is complex). Either method gives me the same result.

Please help.... TIA

Re: WShell.Exec()... complex command line by Tom

Tom
Wed Sep 17 21:13:37 CDT 2003


"andrew" <andrew_test@hotmail.com> wrote in message
news:teuhmv8qirbvpcvctiqmlronfmgj4r9112@4ax.com...
> I've written a script that dumps a MySQL db to another MySQL db. The core of
the script is this --->
>
>
> 'Begin Code
>
> strCommand = "C:\mysql\bin\mysqldump --opt -u " & strUser & " -p""" & strPass
& """ " & strSouceDB & " | C:\mysql\bin\mysql -C -u " & strUser & " -p""" &
strPass & """ -h Intranet " & strDestDB
> Set WshShell = CreateObject("WScript.Shell")
> Set objExec = WshShell.Exec(strCommand)
>
> 'End Code
>
>
> yeah... I realize the command line is ugly.
>
> Here's the ouput from stdERR:
>
> C:\mysql\bin\mysqldump: Got error: 1064: You have an error in your SQL syntax
> near '| READ /*!32311 LOCAL */,C:\mysql\bin\mysql READ /*!32311 LOCAL */,- C
READ /*!32' at line 1
>
>
>
> I can do this ---> "WScript.Echo strCommand" and output the command line, then
paste it in a
> cmd window and it runs flawlessly. So the command line is being built
correctly... or so I think.
> So my guess is that WScript.Exec( ) is dying somehow because of strCommand.
> I've tried the Chr(34) method instead of escaping the quotes around strPass
(yes
> they have to be there cause the password is complex). Either method gives me
the same result.
>
> Please help.... TIA
>



Hi there. That really is a scary looking line.
I think your problem may be with the pipe character |
because WScript is not running through the cmd processor
which would explain why it works if you paste it.

I would try putting cmd.exe at the beginning of the whole line.








Re: WShell.Exec()... complex command line by Michael

Michael
Wed Sep 17 21:24:16 CDT 2003

andrew wrote:
> I've written a script that dumps a MySQL db to another MySQL db. The
> core of the script is this --->
>


You need the command shell to support the pipe | operator.

Try:

strCommand = "%COMSPEC% /C C:\mysql\bin\mysqldump..." & etc

>
> 'Begin Code
>
> strCommand = "C:\mysql\bin\mysqldump --opt -u " & strUser & " -p""" &
> strPass & """ " & strSouceDB & " | C:\mysql\bin\mysql -C -u " &
> strUser & " -p""" & strPass & """ -h Intranet " & strDestDB Set
> WshShell = CreateObject("WScript.Shell")
> Set objExec = WshShell.Exec(strCommand)
>
> 'End Code
>
>
> yeah... I realize the command line is ugly.
>
> Here's the ouput from stdERR:
>
> C:\mysql\bin\mysqldump: Got error: 1064: You have an error in your
> SQL syntax
> near '| READ /*!32311 LOCAL */,C:\mysql\bin\mysql READ /*!32311 LOCAL
> */,- C READ /*!32' at line 1
>
>
>
> I can do this ---> "WScript.Echo strCommand" and output the command
> line, then paste it in a
> cmd window and it runs flawlessly. So the command line is being
> built correctly... or so I think.
> So my guess is that WScript.Exec( ) is dying somehow because of
> strCommand.
> I've tried the Chr(34) method instead of escaping the quotes around
> strPass (yes
> they have to be there cause the password is complex). Either method
> gives me the same result.
>
> Please help.... TIA

--
Michael Harris
Microsoft.MVP.Scripting

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

System Administration Scripting Guide - samples scripts
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


Re: WShell.Exec()... complex command line by andrew

andrew
Thu Sep 18 12:32:29 CDT 2003


Thank you for the prompt, and correct response.... works great.

I'm thankful for people who are much smarter than I.



On Wed, 17 Sep 2003 19:24:16 -0700, "Michael Harris \(MVP\)" <mikhar@mvps.org> wrote:

>You need the command shell to support the pipe | operator.
>
>Try:
>
>strCommand = "%COMSPEC% /C C:\mysql\bin\mysqldump..." & etc


Re: WShell.Exec()... complex command line by Michael

Michael
Thu Sep 18 20:22:34 CDT 2003

>... people who are much smarter than I.

Make that:

"...who have been around longer and have been burned in every conceivable
way"...


--
Michael Harris
Microsoft.MVP.Scripting