Hacker News new | ask | show | jobs
by sauravc 4783 days ago
Seems pretty easy in python:

  from subprocess import call
  call(["ls", "-l"])
or

  import os
  os.system("ls -l")
2 comments

The difference between "pretty easy" and "easy" changes everything.

Compare

  from subprocess import call
  call(["ls", "-l"])
to

  `ls -l`
I really like the python sh library for stuff like this. Would you rather do what you wrote, or this?

    for listing in ls('-l'):
        '''etc'''
Here's the library in question - https://pypi.python.org/pypi/pbs - it makes me super happy to do shell work in python.
Wow, that's a neat library. You can just import any program and use it like a function (from sh import grep)! Thanks for the link. Also, sh documentation: http://amoffat.github.io/sh/
Yeah, it's replaced just a ton of boilerplate `def run(*args):` functions wrapping Popen. I couldn't be happier.
i use Sh to interface with my cmus player. from sh import cmus_remote! :)
While there are several ways to skin that cat, the suggested way is to use subprocess.Popen .

Also, when using Popen, calling .wait() can cause problems if you are expecting large amounts of info back from stdin or stderr. Using .communicate() is generally better.

this. python has too many ways to skin the cat.
hehe, while I do agree in this particular situation, it's rather funny to see that in writing.