4

I want to run a long process (calculix simulation) via python.

As mentioned here one can read the console string with communicate().

As far as I understand the string is returned after the process is completed? Is there a possibility to get the console output while the process is running?

2
  • Your process calculix simulation write data on console while running ? Commented Apr 4, 2014 at 10:09
  • yes, sure it writes to console Commented Apr 4, 2014 at 10:15

2 Answers 2

2

You have to use subprocess.Popen.poll to check process terminates or not.

while sub_process.poll() is None:
    output_line = sub_process.stdout.readline()

This will give you runtime output.

Sign up to request clarification or add additional context in comments.

Comments

1

This should work:

sp = subprocess.Popen([your args], stdout=subprocess.PIPE)
while sp.poll() is None: # sp.poll() returns None while subprocess is running
  output = sp.stdout # here you have acccess to the stdout while the process is running
  # Do stuff with stdout

Notice we don't call communicate() on subprocess here.

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.