0

how can I automatically press enter inside a batch-file? (Background: I want to create and execute an mysql-dump via batch (what works basically).Before the creation of the dump-file the system asks me for a passwort. Because I don´t have one, I only have to press enter to start the process) I want to fully automize the process and time it via task scheduler) That´s what I have so far:

@echo off
cd C:\Program Files\MySQL\MySQL Workbench 6.3 CE
mysqldump -h 168.192.100.1 -P 3306 -u user -p DB1 > C:\SQLDump\Db1_dump.sql
WScript.Sleep 2000
mysql -h 168.192.100.1 -P 3306 -u user -p DB1_Copy < C:\SQLDump\Db1_dump.sql
pause

Another possibility I found on the net was to solve it with 2 files (1 bat and 1 .vbs:

I adapted the example to my needs, but it´s not working;

(Bat.file named UpdateSQLDump.bat)

@echo off
cd C:\Program Files\MySQL\MySQL Workbench 6.3 CE
mysqldump -h 168.192.100.1 -P 3306 -u user -p DB1 > C:\SQLDump\Db1_dump.sql
start UpdateSQLDumpEnter.vbs
mysql -h 168.192.100.1 -P 3306 -u user -p DB1_Copy < C:\SQLDump\Db1_dump.sql
pause

(vbs.file named UpdateSQLDumpEnter.vbs)

dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 100
WshShell.AppActivate "UpdateSQLDump.bat"
WScript.Sleep 100
for j = 0 to 2
WshShell.SendKeys "ENTER"
WScript.Sleep 400
next

How can I solve the problem?

AbsoluteBeginner
  • 485
  • 4
  • 13
  • check [this](http://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx) - you should use `~` or `{ENTER}` instead of `ENTER` – npocmaka Jan 12 '17 at 13:31

1 Answers1

0

Not exactly what you are asking for, but: If your user has no password you can omit the -p, in which case MySQL will not prompt you for a password at all.

jesper_bk
  • 503
  • 2
  • 9