3

I'm a relative novice when it comes to code, so if I'm missing the obvious please excuse me; my issue is getting SQLite3 (version 3.7.15.2 to be exact) to work in Powershell. I installed SQLite3 on my computer and the SQLite3 shell works fine on its own, but when I attempt to use SQLite3 via Powershell I get error messages.

If I just type in the sqlite3 in Powershell it states that it is not a recognized command; however, when I attempt to run a basic SQL script via the following commands in Powershell I get this error message instead:

sqlite3 ex1.db < ex1.sql

error message: "The '<' operator is reserved for future use

With all of this being said, what could be the issue?

Thanks for your time!

4 Answers4

7

"<" (stdin) redirection is not supported in Powershell.

Perhaps you can try to put your cammands in a file sqlcmd.txt and try :

Get-Content sqlcmd.txt | sqlite3.exe > output.txt

Be careful to use the full path for your exe if it's not into the PATH.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
1

The following command works on OSX and Linux:

sqlite3 ex1.db < ex1.sql

But somehow, it does not work on Windows 10 PowerShell :(

Zed Shaw in his "Learn SQL The Hard Way" book has this solution for PowerShell:

sqlite3 ex1.db -init ex1.sql

Replace "<" with "-init"

"-init" must precede the .sql script, so the command could also be written:

sqlite3 -init ex1.sql ex1.db
KirstieBallance
  • 1,238
  • 12
  • 26
0

In Powershell, if you want to run an exe located in the current directory, you must prefix it with .\, like so:

.\sqlite3 ex1.db

You can use the full path as well:

"drive-letter:\path_to_sqlite\sqlite3" ex1.db
chue x
  • 18,573
  • 7
  • 56
  • 70
  • I'm not quite sure what this has to do with the question. The error message 'error message: "The '<' operator is reserved for future use' is quite certainly caused by something else. – Andrew Savinykh Feb 08 '13 at 08:01
  • @zespri - the OP indicates first and foremost that when he types `sqlite3` that the command is not recognized. This indicates to me that he is trying to run sqlite from the current directory. The way to solve this is with my solution above. – chue x Feb 08 '13 at 13:58
-2

After judicious googling, I have determined that this is in fact the correct answer:

get-content ext1.sql | sqlite3 ext1.db

Originally found here: https://stackoverflow.com/a/17077104/1469375

JP's answer will create an empty file named "output.txt", but won't place the contents of sqlcmd.txt into the file.

Community
  • 1
  • 1
Tom
  • 179
  • 7