output from external commands

Discussion in 'Python' started by James Colannino, Oct 24, 2005.

  1. Hey everyone. First off, I'm new to the list. I had had a little bit
    of experience with Perl before discovering Python. The more Python I
    learn, the more I love it :) I just have a quick question to ask. I
    know that this is probably a simple question, but I've been googling
    around, and partly because I'm not sure exactly what to search for, I've
    been unsuccessful at finding an answer. What I'd like to do is be able
    to take the output of an external command and assign it as an array of
    strings. So, for example, in Perl I could do something like:

    @files = `ls`;

    So I guess I'm looking for something similiar to the backticks in Perl.
    Forgive me if I've asked something that's a bit basic for this list.
    Any help would be greatly appreciated :) Thanks very much in advance.

    James

    --
    My blog: http://www.crazydrclaw.com/
    My homepage: http://james.colannino.org/
     
    James Colannino, Oct 24, 2005
    #1
    1. Advertising

  2. James Colannino

    Mike Meyer Guest

    James Colannino <> writes:

    > Hey everyone. First off, I'm new to the list. I had had a little bit
    > of experience with Perl before discovering Python. The more Python I
    > learn, the more I love it :) I just have a quick question to ask. I
    > know that this is probably a simple question, but I've been googling
    > around, and partly because I'm not sure exactly what to search for,
    > I've been unsuccessful at finding an answer. What I'd like to do is
    > be able to take the output of an external command and assign it as an
    > array of strings. So, for example, in Perl I could do something like:
    >
    > @files = `ls`;
    >
    > So I guess I'm looking for something similiar to the backticks in
    > Perl. Forgive me if I've asked something that's a bit basic for this
    > list. Any help would be greatly appreciated :) Thanks very much in
    > advance.


    This is a scripting language feature. Python doesn't have direct
    support for it, any more than C++ does. To get that functionality, you
    want to use either the os.popen function, or - preferable, but only
    available in newer Pythons - the subprocess module.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Oct 24, 2005
    #2
    1. Advertising

  3. Mike Meyer wrote:

    >This is a scripting language feature. Python doesn't have direct
    >support for it, any more than C++ does. To get that functionality, you
    >want to use either the os.popen function, or - preferable, but only
    >available in newer Pythons - the subprocess module.
    >
    >


    Thanks.

    James

    --
    My blog: http://www.crazydrclaw.com/
    My homepage: http://james.colannino.org/
     
    James Colannino, Oct 24, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    4,013
    Thomas Stegen
    Jun 28, 2003
  2. Avi Kak
    Replies:
    4
    Views:
    444
    Fernando Perez
    Jul 26, 2004
  3. darren kirby

    Re: output from external commands

    darren kirby, Oct 24, 2005, in forum: Python
    Replies:
    6
    Views:
    396
    Fredrik Lundh
    Oct 24, 2005
  4. darren kirby

    [OT] Re: output from external commands

    darren kirby, Oct 25, 2005, in forum: Python
    Replies:
    2
    Views:
    352
    Tony Meyer
    Oct 25, 2005
  5. Terry Hancock

    Re: [OT] Re: output from external commands

    Terry Hancock, Oct 25, 2005, in forum: Python
    Replies:
    2
    Views:
    291
    Bengt Richter
    Oct 26, 2005
Loading...

Share This Page