1

I need to read out the text from a cmd prompt window (which updates every second) in my Python program. I'm using Windows 7. Anyone have an idea how to do this?

edit:

I didn’t explain it very well. The cmd prompt is already open and I need to read out everything it prints. I have to "link" my Python program to the command prompt.

6
  • Google "python input" ? Commented Mar 5, 2014 at 12:12
  • 1
    Do you mean you need to scrap the window's text (actually, any window's text) by running a python script? Commented Mar 5, 2014 at 12:23
  • Yeah, thats what i need to do Commented Mar 5, 2014 at 12:26
  • In windows to access the terminal you specific the file "CON" or "CON:" (linux equivalent of /dev/tty). I would try something like while True: print(open("CON:").read()) Commented Mar 5, 2014 at 12:27
  • that did not work for me =( Commented Mar 5, 2014 at 12:43

3 Answers 3

1

You should read :module-subprocess

>>> subprocess.check_output(["echo", "Hello World!"])
'Hello World!\n'
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried sys.argv ?.

import sys
print sys.argv[1:]

The first argument will be your file name.

Comments

0

Just do subprocess.check_output()

import subprocess
command = "dir"
output = subprocess.check_output(command, shell=True, text=True)
print(output)

Don't forget to add shell=True and text=True argument

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.