Hi,

I have a Python script that calls a program that only prints to the terminal [yes I tried to force it to print to file ... no luck]. However, I need to save the output of the terminal to file in order to perform further analysis. In the code I tried running (the linux/unix command) script, via subprocess.call before the main code executes.

subprocess.call(["script", "scripttest.txt])
#Main Code starts
#and prints a lot of info to terminal
#Main code ends
subprocess.call("exit", shell=True)

However, while the python script successfully calls script, it "ends" before running the main code. The main code will only continue after I invoke CRTL-D (or type exit) to end script in the terminal, but doing this, the output isn't saved.

Does anyone have any ideas on how to get around this or another way to save the output?
I can copy from the terminal to file, however this is not efficient for many iterations!

Cheers,

See if this works ...
subprocess.call(["script", "scripttest.txt]).wait()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.