windows - Windows 7 上可执行文件的 MySQLDump

标签 windows git exec mysql wsh

我尝试通过调用 wsh jscript 文件来转储 mysql 数据库,但它不起作用。

我有这段代码,用 git shell 调用,它工作得很好:

# If something fails, exit with status other than 0
set -e

# select dump directory
cd "$(git rev-parse --show-toplevel)"

# first, remove our original schema
rm -f "WebShop\DataBase\backup.sql"

# generate a new schema
exec "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop\DataBase\backup.sql"

我在 WSH 中尝试了几乎相同的代码,但它仅返回转储文件的 header ,并且不创建文件。我不知道出了什么问题,或者如何调试代码......:S

var shellObj = WScript.CreateObject('WScript.Shell');
var exec = shellObj.Exec(
    '"C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe"'+
    " --skip-comments -u root --password=root webshopdb |sed 's$),($),\\n($g' > " + 
    '"D:\\creation\\software developer\\projects\\webshop-refactoring-project\\document root\\WebShop\\DataBase\\backup.sql"'
);
WScript.Echo(exec.StdOut.ReadAll());

我也尝试过使用bat文件和cmd文件,但它们无法处理路径中的空间。

有人可以帮忙吗?

(对我来说,从 git 代码中创建一个可执行文件就足够了,或者让 wsh 工作......完美的解决方案是如果我可以从 netbeans 调用转储,但在生活中没有什么比这更理想的了。 ..:D)

最佳答案

我是通过文件关联做到的。

我创建了一个 git.bat 文件:

if not exist %1 exit
set bash=C:\Program Files (x86)\Git\bin\bash.exe
"%bash%" --login -i -c "exec "%1""

并将其关联到 .hook 文件。

之后我创建了一个测试 dump.hook 文件:

#!/bin/sh
cd "D:/creation/software developer/projects/webshop-refactoring-project/document root/WebShop";
cd "$(git rev-parse --show-toplevel)"
rm -f "WebShop/DataBase/backup.sql"
exec "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop/DataBase/backup.sql"
exit

而且效果非常好。

三天后我收到了!呜呼! :D

注意:*Windows命令提示符通常会出现路径名中空格和特殊字符的问题,因此使用git的模拟linux比尝试修复它要容易得多。也可以将 .hook 文件源到预提交 git hook 中,这样它就可以在每次提交时自动转储数据库模式...(也许 git add 不适用于这些文件,我还没有找到自动转储并提交解决方案: git pre-commit + mysqldump: cannot find path, not existing command ) *

关于windows - Windows 7 上可执行文件的 MySQLDump,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254186/

相关文章:

windows - Spy++ 和窗口在失去焦点时关闭

c - Windows 服务器上的 KMDF

perl - perl 中的 xargs 等价物

go - 在 Golang 中将字符串通过管道传输到命令的 STDIN

c - 如何使用正确的参数在 C 中调用 execl()?

php - 这个 zend 框架路径是如何工作的?

c++ - 使用 C uder Window OS 将系统时钟与 UTC 时间同步

git - 位桶 ssh_exchange_identification : read: Connection reset by peer

git - 切换 Git 以使用 SSH

git - 如何最好地与 SmartGit 共享代码