It seems that sqlite3.exe (console) doesn't work as a subprocess with pipes.

I've tried it with both C++ code calling the CreateProcessW win32 API and
with python and both resulted in the same behaviour. Which is the
sub-process doesn't return anything when I try and read it's output (just
hangs). I'm expecting the signon and prompt messages to be printed via
stdout and readable by the parent process. Both C++ + python work fine with
other binaries (cmd.exe for instance). So I very much doubt it's my code or
environment (Win7).

Here is my python code:

import os
import sys
import subprocess

if 0:
    p = subprocess.Popen(["C:\\Windows\\system32\\cmd.exe"],
stdout=subprocess.PIPE)
else:
    p = subprocess.Popen(["sqlite3.exe", "Database.sqlite"],
stdout=subprocess.PIPE)

if p is None:
    print "Error creating process."
else:
    while p.poll() == None:
        resp = p.communicate()
        print len(resp[0]), resp[0]



I expect there is something funny going on with sqlite3.exe's stdout/stdin.
But I'm not immediately clear what that is looking at it's code. Why
doesn't it work like other console processes?

The problem I'm trying to solve is:
When my application that uses an sqlite3 database gets the "database disk
image is malformed" I need to be able to give the user a "repair" option
which dumps the datrabase to an .sql file and reimport it all. I'm assuming
the best way is to do that via the shell rather than try and copy all the
dump code into my own application.

Based on
http://froebe.net/blog/2015/05/27/error-sqlite-database-is-malformed-solved/

Regards
Matthew

Reply via email to