From 23b3dc9d0323073792d5eb87760616be1debf728 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 29 Aug 2021 14:43:13 -0700 Subject: RUN: combine creating the temporary file with running the command Should improve performance, especially when connection latency is high. Signed-off-by: Sean Whitton --- src/connection.lisp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/connection.lisp') diff --git a/src/connection.lisp b/src/connection.lisp index 94ad848..efd86ad 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -449,20 +449,25 @@ Keyword arguments accepted: Returns command's stdout, stderr and exit code, unless :FOR-EXIT, in which case return only the exit code." (%process-run-args - (let* ((stdout (mktemp)) - (wrapped (format nil "( ~A ) >~A" cmd stdout))) + (let (stdout + (wrapped + (format + nil "tmpf=$(~A) && printf \"%s\\n\" \"$tmpf\" && (~A) >\"$tmpf\"" + (load-time-value (mkstemp-cmd) t) cmd))) (handler-bind ((serious-condition (lambda (c) (declare (ignore c)) - (connection-run - *connection* - (format nil "rm -f ~A" (escape-sh-token stdout)) - nil)))) + (when stdout + (connection-run + *connection* + (format nil "rm -f ~A" (escape-sh-token stdout)) + nil))))) (informat 4 "~&RUN ~A" (if (> *consfigurator-debug-level* 4) wrapped cmd)) (multiple-value-bind (err exit) (connection-run *connection* wrapped input) + (setq err (lines err) stdout (car err) err (unlines (cdr err))) (let ((out (connection-readfile-and-remove *connection* stdout))) (when inform (informat 1 "~& % ~A~%~{ ~A~%~}" -- cgit v1.2.3