SQLite User Forum

SQLite won’t .quit from Windows PowerShell
Login

SQLite won't .quit from Windows PowerShell

(1) By anonymous on 2023-01-09 12:28:57 [link] [source]

When running sqlite3.exe from a PowerShell script, SQLite will not quit back to the PowerShell command after encountering a .quit command in a script

Is this intended behaviour?

To reproduce:
create a file called sqlitequit.sqlite3 containing

.show
.quit

run the command below from a PowerShell window.
.\sqlite3.exe -init .\sqlitequit.sqlite3

I would expect the .show and .quit commands to be executed and the Powershell prompt (PS) to shown, currently the SQLite prompt (sqlite>) is shown.

(2.1) By Keith Medcalf (kmedcalf) on 2023-01-09 16:12:00 edited from 2.0 in reply to 1 [link] [source]

This has nothing whatsoever to do with PowerSmell. It has to do with the fact that you are trying to .quit in an init script. You cannot do that. It does not matter what is causing the sqlite3 debugging CLI to execute, a .quit command in an init script is ignored.

In other words, your expectation is incorrect.

(3) By Larry Brasfield (larrybr) on 2023-01-09 18:04:58 in reply to 2.1 [link] [source]

a .quit command in an init script is ignored.

Not quite. Consider this script: .quit .print Not quitting!

The effect of the .quit is to end execution of the present input stream. In an init script or a script input via .read, it has just that effect; it is not ignored. The 2nd line will not execute.

It is only when .quit is interpreted from the primary/only input stream that it means "No more input, so quit the program."

(4) By Keith Medcalf (kmedcalf) on 2023-01-09 18:15:51 in reply to 3 [link] [source]

Hrm. You are (of course) correct.

The .help should be updated to indicate that .quit quits the input stream (same as EOF) and only exits the program if there is no more input.

I don't know if there is online documentation, but it should get the same update.

(5.1) By Larry Brasfield (larrybr) on 2023-01-09 18:52:27 edited from 5.0 in reply to 4 [link] [source]

The .help should be updated to indicate that .quit quits the input stream (same as EOF) and only exits the program if there is no more input.

Yes, it should. Done.

I don't know if there is online documentation, but it should get the same update.

Even better. This behavior has been a frequent point of puzzlement,1 on my part and others'.

The minimal mention there has been clarified the same way.


  1. ^ I added a command, .cease , to a private version because I wanted a real quit, but ".exit 0" does that so .cease is redundant.

(6) By anonymous on 2023-01-10 13:47:03 in reply to 2.1 [source]

Is there a way to run a SQLite script from PowerShell that exits back to the PS command prompt?

(7) By Richard Hipp (drh) on 2023-01-10 14:01:34 in reply to 6 [link] [source]

Instead of ".quit", use ".exit 1"