-5

I have a 3rd party software which i run on Linux platform, this gives me a output for every 10 seconds. Is there any way in python to capture the screen contents thrown after every 10 seconds to a file a via python.

I do not want to run this 3rd party software command via sub process.

sKen
  • 105
  • 1
  • 2
  • 16
  • 1
    does the 3rd party program save this output as txt or something else? – Roy Holzem Aug 02 '17 at 07:41
  • if the 3rd party program doesn't log the output somewhere else than on console, it will be really difficult without using subprocess – Cédric Julien Aug 02 '17 at 07:42
  • No it does not save the output for me any where. It just prints on the screen. – sKen Aug 02 '17 at 07:51
  • Can you try redirecting the output? In Linux you can do it by running the program with the ">" redirect and point stdout and stderr to the same file. Say your program is "foo" and you call it from the command line with "foo" Then you can redirect to file with "foo > allout.txt 2>&1". Sauce: https://stackoverflow.com/questions/6674327/redirect-all-output-to-file. It works similarilly for Windows programs. – BoboDarph Aug 02 '17 at 07:59

1 Answers1

0

You don't need a python script to redirect output from a program to a file. The Linux bash already gives you the option to redirect output of running programs to files with the ">" or ">>" operators.

Source: Redirect all output to file

But since you want a pythonic solution, you could just use Popen.communicate to start your program and dump the output of its stdout/stderr to a variable in a python script that you can then use to write to a file. Source: How can I capture the stdout output of a child process?

BoboDarph
  • 2,751
  • 1
  • 10
  • 15