Print text from a terminal command into shell
Question: I am creating a MS-DOS replica to test out my python skills since I am
particularly new and I'm writing the "dir" command. Right now, the command
opens a terminal that seems to be doing what I want it to be doing, except for
printing it out into a terminal instead of the program output. I want to
transfer the text it creates in the command line to the output of the program,
basically. Here's what I'm using right now:

    
    
    if COMMAND == ("dir"):
        os.system('dir')
    

Anyway, thanks for the help if anyone sees this, since I am pretty nooby at
python and new to this website.


Answer: You could use `subprocess.check_output`.

    
    
    >>> import subprocess
    >>> print subprocess.check_output("dir", shell=True)
     Volume in drive C is System
     Volume Serial Number is E4C1-A0AA
    
     Directory of C:\Users\Kevin
    
    04/30/2015  08:12 AM    <DIR>          .
    04/30/2015  08:12 AM    <DIR>          ..
    03/30/2015  02:51 PM    <DIR>          Contacts
    ...
    

