-1

I have a program in which I'd like to make more effecient.

Basically you press a button and it generates a bit of text. I'm wanting to automatically press that button say ever second, and then take that text that was given, and output it into a file.

I'm not sure what language the program is coded in but I can only code in python. Thanks in advance!

2 Answers2

0

You are able to capture the output of a program from the command line using the > operator to pipe the output of the program into a place you specify. For example if I want to view all of the python packages I have installed through pip on my computer I could use the command pip freeze which would print a list of the installed packages. But if I wanted to capture that output to make a requirements.txt file I could do this pip freeze > requirements.txt which pipes the output of the program to requirements.txt instead of the terminal. Similarly you can provide input to a program using the < operator.

Note: This applies to programs that are run through the command line. Specifically *nix like command lines (so OSX or Linux).

user3282276
  • 3,674
  • 8
  • 32
  • 48
0

You can use the Popen from subprocess. You can run the external command from your python program, send some input to it every few seconds and get whatever it outputs to the standard output.

Have a look at this question for ideas...

How to call an external program in python and retrieve the output and return code?

Community
  • 1
  • 1
sfroid
  • 51
  • 6