On Thu, Oct 8, 2015 at 4:03 PM, Cecil Westerhof <ce...@decebal.nl> wrote: > I want to do the following Bash command in Python: > sqlite3 spreekwoorden.sqlite "SELECT spreekwoord FROM spreekwoorden;" | > sort > spreekwoorden2.txt > > The following does this in Python: > sqlite_pipe = Popen( > ( > 'sqlite3', > 'spreekwoorden.sqlite', > 'SELECT spreekwoord FROM spreekwoorden;' > ), > stdout = PIPE > ) > Popen( > ( > 'sort', > '--output=spreekwoorden2.txt', > ), > stdin = sqlite_pipe.stdout > ) > > Is this the correct way, or is there a better way?
That seems fine to me. Alternatively you could pass shell=True to Popen and then the original command should work verbatim (but see the warnings about using shell=True). -- https://mail.python.org/mailman/listinfo/python-list