get output of cmd-line command under MS windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • calmar

    #1

    get output of cmd-line command under MS windows

    Hi all,

    unfotunately, 'commands.getst atusoutput(comm and)' does not work under
    windows.

    Would there be any alternative?

    os.system also just provides the exit number I think.

    thanks a lot,
    and cheers
    marco


    --
    calmar

    (o_ It rocks: LINUX + Command-Line-Interface
    //\
    V_/_ http://www.calmar.ws
  • Bernard Lebel

    #2
    Re: get output of cmd-line command under MS windows

    You should give a go to os.popen( <system command here> ). Article
    6.1.2 and 6.1.3 in the Python Library doc.

    I recently wrote a program that would create a pipe using the popen()
    method, and would enter a while loop. At each iteration, it would read
    one line of the pipe output, and the loop would break when it gets an
    empty line (indicating the running application is not running in this
    case).

    Example:

    import os

    oPipe = os.popen( "run C:/program files/my app/executable.exe" )

    while 1:
    sLine = oPipe.read()
    print sLine
    if sLine == '':
    print 'No more line from pipe, exit.'
    break



    Cheers
    Bernard


    On 2/8/06, calmar <mac@calmar.w s> wrote:[color=blue]
    > Hi all,
    >
    > unfotunately, 'commands.getst atusoutput(comm and)' does not work under
    > windows.
    >
    > Would there be any alternative?
    >
    > os.system also just provides the exit number I think.
    >
    > thanks a lot,
    > and cheers
    > marco
    >
    >
    > --
    > calmar
    >
    > (o_ It rocks: LINUX + Command-Line-Interface
    > //\
    > V_/_ http://www.calmar.ws
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >[/color]

    Comment

    • Cameron Laird

      #3
      Re: get output of cmd-line command under MS windows

      In article <mailman.1598.1 139411970.27775 .python-list@python.org >,
      Bernard Lebel <3dbernard@gmai l.com> wrote:[color=blue]
      >You should give a go to os.popen( <system command here> ). Article
      >6.1.2 and 6.1.3 in the Python Library doc.
      >
      >I recently wrote a program that would create a pipe using the popen()
      >method, and would enter a while loop. At each iteration, it would read
      >one line of the pipe output, and the loop would break when it gets an
      >empty line (indicating the running application is not running in this
      >case).
      >
      >Example:
      >
      >import os
      >
      >oPipe = os.popen( "run C:/program files/my app/executable.exe" )
      >
      >while 1:
      > sLine = oPipe.read()
      > print sLine
      > if sLine == '':
      > print 'No more line from pipe, exit.'
      > break[/color]

      Comment

      • calmar

        #4
        Re: get output of cmd-line command under MS windows

        On 2006-02-08, Bernard Lebel <3dbernard@gmai l.com> wrote:

        Hi Bernhard and all,
        [color=blue]
        > oPipe = os.popen( "run C:/program files/my app/executable.exe" )
        >
        > while 1:
        > sLine = oPipe.read()
        > print sLine
        > if sLine == '':
        > print 'No more line from pipe, exit.'
        > break
        >[/color]

        I see. I saw also os.popen("...." ).read() or so.

        Anyway, not sure if that would also catch stderr?

        But doesn't matter. It seems, imagemagick (binaries) won't provide
        proper error-codes, but at least when it prints something, something was
        not ok probably.

        I will check the resulting file, to see if everything went ok, and try
        to catch the output like you mentioned.

        thanks a lot
        marco

        --
        calmar

        (o_ It rocks: LINUX + Command-Line-Interface
        //\
        V_/_ http://www.calmar.ws

        Comment

        • calmar

          #5
          Re: get output of cmd-line command under MS windows

          On 2006-02-08, Bernard Lebel <3dbernard@gmai l.com> wrote:

          Hi Bernhard,
          [color=blue]
          > You should give a go to os.popen( <system command here> ). Article
          > 6.1.2 and 6.1.3 in the Python Library doc.
          >[/color]

          that was good, but on python2.4

          subprocess is GREAT! e.g.:

          pipe = subprocess.Pope n(tot, stdout=subproce ss.PIPE,\
          stderr=subproce ss.PIPE, shell=False)
          message = pipe.stdout.rea d()
          error = pipe.stderr.rea d()

          thanks all,
          calmar

          --
          calmar

          (o_ It rocks: LINUX + Command-Line-Interface
          //\
          V_/_ http://www.calmar.ws

          Comment

          • Fredrik Lundh

            #6
            Re: get output of cmd-line command under MS windows

            "calmar" wrote:
            [color=blue]
            > that was good, but on python2.4
            >
            > subprocess is GREAT! e.g.:
            >
            > pipe = subprocess.Pope n(tot, stdout=subproce ss.PIPE,\
            > stderr=subproce ss.PIPE, shell=False)
            > message = pipe.stdout.rea d()
            > error = pipe.stderr.rea d()[/color]

            footnote: subprocess is available for Python 2.2 and later, from



            </F>



            Comment

            Working...