How to use wildcards with messenger

I am trying to run this command through the Enew package for KennethReitz:

$ sqlite3 foo.db 'select * from sqlite_master' 

I tried this:

 r = envoy.run("sqlite3 foo.db 'select * from sqlite_master'") sqlite3: Error: too many options: "*" 

and this:

 r = envoy.run(['sqlite3', 'foo.db', 'select * from sqlite_master']) AttributeError: 'NoneType' object has no attribute 'returncode' 

additional quoting and escaping doesn't seem to help. Any suggestions?

FYI: This is what I should have done now:

 cmd = "sqlite3 %(database)s 'select * from sqlite_master'" % locals() os.system(cmd) 

Please note that this is a contrived example and that most of the unix shell commands that I would like to issue are not just simple choices that can be easily made using SQLAlchemy.

+2
source share
2 answers

You can use subprocess :

 from subprocess import check_output as qx output = qx(['sqlite3', 'foo.db', 'select * from sqlite_master']) print output 

Or sqlite3 module:

 import sqlite3 conn = sqlite3.connect('foo.db') for row in conn.execute('select * from sqlite_master'): print row 

If you still want to use envoy , you can fix it as:

 import envoy r = envoy.run([["sqlite3", "foo.db", "select * from sqlite_master"]]) print r.std_out 
+1
source

This will not work in envoy because the messenger breaks the commands and passes them to the subprocess. Even if you try using subprocess.Popen(command, shell = False) , you will get sqlite3 terminal. Both subprocess and envoy cannot handle this, I will be glad if you can open the problem in envoy , as I contribute to it, I will think about it.

+2
source

Source: https://habr.com/ru/post/921676/


All Articles