def run_command_instance(self, command): """Run Command instance.""" is_shell = True try: process = subprocess.Popen(command.command, stdin=command.stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=is_shell) except OSError: raise CommandNotFound(command.arguments) result = ShResult() result.return_code = process.wait() result.stdout = process.stdout.read() result.stderr = process.stderr.read() return result
def run_command_instance(self, command): """Run Command instance.""" header = '--- BEGIN xal stdout ---' footer = '--- END xal stdout ---' fabric_command = 'echo -n "{header}"' \ '&& {command}' \ '&& echo -n {footer}' \ .format(header=header, command=str(command), footer=footer) fabric_result = fabric.api.run( fabric_command, quiet=True, pty=False, # Avoid issues with newlines. ) result = ShResult() result.return_code = fabric_result.return_code result.stdout = fabric_result.stdout[len(header):-len(footer)] result.stderr = fabric_result.stderr[len(header):-len(footer)] return result