sshanzel
sshanzel

Reputation: 389

VBS opens a CMD but can't read next commands to go on other directory

I am trying to create vbs file so that it will be executed by the MS Scheduler in order to backup my Postgresql database because i can't seem to find a way in using agent since i installed it but it is not appearing in the UI of PGAdmin III that was installed when i used Odoo. I am using windows 10.

Here is my .vbs file

Set ShellCmd = WScript.CreateObject("WScript.Shell")

ShellCmd.run "cmd cd\ cd 'Program Files' cd Odoo 9.0-20161004 cd PostgreSQL cd bin pg_dump -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"

WScript.Echo "Success!"

When i run this, the command line isn't going anywhere. Even just "cmd cd\" the cmd does nothing. I'ts a quite simple problem but i can't get my automated backup working if i can't run a simple vbs command

Upvotes: 0

Views: 228

Answers (2)

user6811411
user6811411

Reputation:

Your ShellCmd is heavily broken. I suggest instead of using .Run take the .Exec method to catch the output - at least until problems are solved. I don't know if your pg_dump requires to be run inside that same folder, if not this might work:

Dim WshShell, oExec, s
Set WshShell = CreateObject("WScript.Shell")

Program = """C:\Program Files\Odoo 9.0-20161004\PostgreSQL\bin\pg_dump"""
Options = " -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"

Set oExec = WshShell.Exec(Program & Options)

Do While Not oExec.StdOut.AtEndOfStream
    s = s & oExec.StdOut.ReadLine() & vbCrLf
Loop

WScript.Echo "oExec.Status=" & oExec.Status
Wscript.Echo s

Upvotes: 0

some1
some1

Reputation: 877

Instead of using a vbs script, you should just use a .bat or .cmd batch file:

c:
cd "\Program Files\Odoo 9.0-20161004\PostgreSQL\bin"
pg_dump -h localhost -p 5432 -U openpg -f 'C:/BackupFiles/Sample.backup' -d 120120161800"

Generally, we do not use ShellCmd.run "cmd ...." in vbs to execute multiple commands in one statement.

Upvotes: 1

Related Questions