Commit d563f348 authored by Guillaume Seguin's avatar Guillaume Seguin

Fix #462: final and error commands were run in non blocking mode

This made them fail when data was being written on standard outputs
parent f23db989
...@@ -29,7 +29,7 @@ import traceback ...@@ -29,7 +29,7 @@ import traceback
import re import re
from . import printcore from . import printcore
from .utils import install_locale, run_command, \ from .utils import install_locale, run_command, get_command_output, \
format_time, format_duration, RemainingTimeEstimator, \ format_time, format_duration, RemainingTimeEstimator, \
get_home_pos, parse_build_dimensions, parse_temperature_report get_home_pos, parse_build_dimensions, parse_temperature_report
install_locale('pronterface') install_locale('pronterface')
...@@ -568,10 +568,10 @@ class pronsole(cmd.Cmd): ...@@ -568,10 +568,10 @@ class pronsole(cmd.Cmd):
logging.error(msg) logging.error(msg)
if not self.settings.error_command: if not self.settings.error_command:
return return
run_command(self.settings.error_command, output = get_command_output(self.settings.error_command, {"$m": msg})
{"$m": msg}, if output:
stderr = subprocess.STDOUT, stdout = subprocess.PIPE, self.log("Error command output:")
blocking = False) self.log(output.rstrip())
def promptf(self): def promptf(self):
"""A function to generate prompts so that we can do dynamic prompts. """ """A function to generate prompts so that we can do dynamic prompts. """
...@@ -1392,11 +1392,12 @@ class pronsole(cmd.Cmd): ...@@ -1392,11 +1392,12 @@ class pronsole(cmd.Cmd):
if not self.settings.final_command: if not self.settings.final_command:
return return
run_command(self.settings.final_command, output = get_command_output(self.settings.final_command,
{"$s": str(self.filename), {"$s": str(self.filename),
"$t": format_duration(print_duration)}, "$t": format_duration(print_duration)})
stderr = subprocess.STDOUT, stdout = subprocess.PIPE, if output:
blocking = False) self.log("Final command output:")
self.log(output.rstrip())
def recvcb(self, l): def recvcb(self, l):
if tempreading_exp.findall(l): if tempreading_exp.findall(l):
......
...@@ -108,10 +108,16 @@ def prepare_command(command, replaces = None): ...@@ -108,10 +108,16 @@ def prepare_command(command, replaces = None):
def run_command(command, replaces = None, stdout = subprocess.STDOUT, stderr = subprocess.STDOUT, blocking = False): def run_command(command, replaces = None, stdout = subprocess.STDOUT, stderr = subprocess.STDOUT, blocking = False):
command = prepare_command(command, replaces) command = prepare_command(command, replaces)
if blocking: if blocking:
return subprocess.call(command) return subprocess.call(command, stderr = stderr, stdout = stdout)
else: else:
return subprocess.Popen(command, stderr = stderr, stdout = stdout) return subprocess.Popen(command, stderr = stderr, stdout = stdout)
def get_command_output(command, replaces):
p = run_command(command, replaces,
stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
blocking = False)
return p.stdout.read()
class RemainingTimeEstimator(object): class RemainingTimeEstimator(object):
drift = None drift = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment