Piping external commands

S

saibotorama

What is the Python translation for this Bash statement:

tar cf - "${files[@]}" | bzip2 > "$file".tar.bz2

(Ignoring the fact that "tar cjf" also exists...)

In other words, how does one pipe together arbitrary commands?
 
S

Simon Forman

What is the Python translation for this Bash statement:

tar cf - "${files[@]}" | bzip2 > "$file".tar.bz2

(Ignoring the fact that "tar cjf" also exists...)

In other words, how does one pipe together arbitrary commands?

For piping subcommands check out the subprocess module, especially
http://docs.python.org/lib/node242.html , for bzip2 check out the bz2
module http://docs.python.org/lib/module-bz2.html , but note, there's
also a tarfile module http://docs.python.org/lib/module-tarfile.html
which can handle bzip2 as well.

HTH,
~Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top