5

I've looked for a function to execute a shell command in a SQLite query, e.g., a function exec() that would execute the given command.

Is there such function in SQLite?

2
  • For the complete function list in SQLITE refer This LiNK and for exec() refer this LINK. I hope this might solve your problem. Commented Apr 3, 2017 at 13:55
  • But this is a C-interface? Could I not execute the shell command from plain SQL? Commented Apr 3, 2017 at 14:01

2 Answers 2

4

When you are inside SQLite shell, you can execute any shell command using the ".shell" command without exiting out of the SQLite shell. For example:

.shell echo "Hi there!"

prints the greeting (using OS's echo command) and continues to stay inside the SQLite shell.

Sign up to request clarification or add additional context in comments.

Comments

1

SQLite is designed for small embedded systems, which might not even have a shell. So there is no exec() among the built-in functions.

However, it would be easy to create your own user-defined function to wrap the system() C function.

4 Comments

So, I cannot have the SQLite execute commands like nslookup like it is possible for MS SQL Server through use of EXECUTE()?
Is there a function then that allows writing to a file? I'd like to create a trigger that will "push" new rows to a pipe with a process listening on the other side. Sort f like messaging queue. This would awesome
@TheRealChx101 There is no built-in function for that. (Again, the shell has a user-defined function.)
@TheRealChx101: I use this extention: sqlite.org/src/file/ext/misc/fileio.c. This works like a charme, If you remove the SQLITE_DIRECTONLY flag in the call of sqlite3_create_function (in fileio.c) which creates the writfile() function you can use it even in triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.