Shell 从批处理文件自动创建SQLite数据库
在windows平台上,我有以下功能:Shell 从批处理文件自动创建SQLite数据库,shell,sqlite,batch-file,build,Shell,Sqlite,Batch File,Build,在windows平台上,我有以下功能: schema.sql(包含sql脚本) sqlite3.exe(sqlite命令shell->从sqlite.org下载) build.bat:一个批处理文件,行为:sqlite3.exe-init schema.sql default.db3 当我运行build.bat时,数据库按预期创建,但是sqlite shell不会自动终止。那么,如何让批处理文件运行并自动终止sqlite命令shell呢 例如,输出: C:\Work\X\Database
(包含sql脚本)schema.sql
(sqlite命令shell->从sqlite.org下载)sqlite3.exe
:一个批处理文件,行为:build.bat
sqlite3.exe-init schema.sql default.db3
C:\Work\X\Database>sqlite3.exe -init schema.sql default.db3
-- Loading resources from schema.sql
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
试着这样称呼它:
echo .quit | sqlite3.exe
或者把
.quit
放在你的文件末尾。我同意安德烈的观点。如果不起作用,请尝试在schema.sql末尾的单独一行中添加“quit”
我希望这能有所帮助。试试:
type schema.sql | sqlite3 default.db3
打高尔夫球安德烈的回答,你也可以跑:
echo | sqlite3
EOF将关闭sqlite3(因为您尚未显示其内容),bat
文件缺少exit
语句。您可以自己添加:
sqlite3.exe -init schema.sql default.db3 .exit
我在sqlite3 3.11中遇到了同样的问题(但在3.8中没有),对我有效的解决方案是:
sqlite3.exe default.db3 < schema.sql
sqlite3.exe default.db3
瑞吉斯的回答也很好。你能发布build.bat文件吗?批处理文件包含以下内容作为其唯一条目:sqlite3.exe-init schema.sql default.db3echo.quit | sqlite3.exe-init schema.sql default.db3这对我有效。但是,将.quit放在文件末尾并没有。请也解释一下答案。