the built-in commands module will give you what you want:  
http://docs.python.org/library/commands.html#commands.getoutput

however, the commands module has been deprecated in favor of the subprocess 
module. i'm not sure why they can't just rewrite the commands module to use the 
subprocess module, but here are some functions that fill that purpose:
from subprocess import *
def get_status_output(cmd, input=None, cwd=None, env=None):
    pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)

    (output, errout) = pipe.communicate(input=input)
    assert not errout

    status = pipe.returncode

    return (status, output)

def get_status_output_errors(cmd, input=None, cwd=None, env=None):
    pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=PIPE)

    (output, errout) = pipe.communicate(input=input)

    status = pipe.returncode

    return (status, output, errout)

def get_output(cmd, input=None, cwd=None, env=None):
    return get_status_output()[1]

-chad


On May 29, 2011, at 12:42 PM, efecto wrote:

> Hi there.
> 
> Does anyone know a good way to catch output in shell(linux
> environment) to a string in Maya?
> 
> import os
> cmd = 'myCommand file'
> os.system(cmd) # this spits out results in shell
> I want to catch this this results to a string inside maya for some
> use.
> 
> thank you.
> D
> 
> -- 
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings: 
> http://groups.google.com/group/python_inside_maya/subscribe

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to