I am writing a VBScript script to execute an SQL query in the SQLite shell and was wondering if I needed to use .quit or .exit.
When I set up a task in the task scheduler to run this VBScript script, the SQLite shell doesn’t exit/quit properly due to which I get a new instance created every time the task scheduler run and this is causes the SQL query to not be executed. When I double click on the VBScript script it runs fine and SQLite shell exists gracefully.
How can I fix this?
The script:
开发者_如何学运维Dim objShell
Dim main_database_file, main_output_file, main_sqlite_file
Dim TAB, LINE
' Set default values here if necessary
main_database_file = "G:\example\data\reporting\lastmonth"
main_sqlite_file = "G:\example\sqlite-shell.exe"
main_output_file="G:\example\scripts\display-time.csv"
Set objShell = createObject("Wscript.Shell")
sql = "select * from project;"
objShell.Run """"& main_sqlite_file &"""" & """"& main_database_file &""""
WScript.Sleep(500)
objShell.Sendkeys(".separator ,{ENTER}")
objShell.Sendkeys(".headers ON{ENTER}")
objShell.Sendkeys(".output '" & main_output_file &"'{ENTER}")
objShell.Sendkeys(sql & "{ENTER}")
WScript.Sleep(500)
objShell.Sendkeys(".quit{ENTER}")
Set objShell = Nothing
Well, according to the documentation, the description of both .quit
and .exit
is "Exit this program", so I don't believe so, no.
I would agree with Jack that the doc states no difference. However, why not pipe your commands in to the Command-Line-Processor? You can create a 'SQL' file containing each of the steps above and then execute the single run command:
Something like (not tested!)
SQL file:
.separator ,
.headers on
etc..
Then run this file as:
shell.run "sqlite-clp.exe mydb.db < sqlfile.sql"
There isn't any need for arbitrary timeouts, and you can probably pass in parameters too.
PS: It's probably sendkeys running in the context of a scheduled task that is the problem
I think the only difference is .quit
doesn't work on some Unix systems.
精彩评论