Hopefully a simple problem, using subprocess.check_output I am trying to execute sqlite3 and read in the output. There is a flag available for the sqlite3 CLI where you can initiate it with "-separator ','" to change the divider for output to a comma. It works at the command line, if I include it like this;
sqliteOutput = subprocess.check_output(["sqlite3 "," -separator ',' ",dbLocation,"SELECT blah from argh"])
Then it fails with an sqlite3 CLI error, "Error: too many options"
and quotes the SELECT statement, but if I just run the command as above on a shell without the format for the subprocess command it works as expected.
If I run it again without the separator it runs perfectly, like so;
sqliteOutput = subprocess.check_output(["sqlite3 ",dbLocation,"SELECT blah from argh"])
Obviously I am either mis-understanding how it is interpreting the separator argument in the subprocess, is there a way I can modify it to function correctly? For the inquisitive, I cannot use the sqlite3 python library for this.
here's a correction:
["sqlite3 ", " -separator ',' ", dbLocation, "SELECT blah from argh"] # yours
["sqlite3", "-separator", ",", dbLocation, "SELECT blah from argh"] # mine
the space in the beginning of " -separatator" is wrong.
having "separator" and "," in one argument is wrong too.
space at the end of "sqlite3 " is wrong as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.