From patchwork Mon Mar 16 15:47:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1993 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676111; bh=9neoulUhRQRZ/pQeuyitmn0O/1CDDli+7sUy6NEYjwM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=p7kub8zx3LiREgkP8mSwHMu6L9/v8sHI61Z0ox6+LCG1KbCg28PhcXVzFlm1ldvmb K4IuqKmle+MBIyGda6vrubVAuoEfx/9UDXEcJZUqYvQ35etJjZBnpjMgwUzH1JS7ry Dg90aUy+1lipVj3U8KiGAtJWgBOtMEtk+4DVLbzleATFNQS0PO7aqTNGxnSuSuwIpc fYizzId/FQD/JkwjO7q9K5LCRWdhqrnUV1jSlYJTAqrQ1I3Rhu6ovdd14YY6TuhH+w hdAvprVpj2xdxp41avwk0Nh3McGSk2ZNItIvylKyCVYFWx7bSBooCic/YcTM/fv4gL +PizxbdB4BmaQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D68766A082 for ; Mon, 16 Mar 2026 09:48:31 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id BfL_2mUlSYMO for ; Mon, 16 Mar 2026 09:48:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676111; bh=9neoulUhRQRZ/pQeuyitmn0O/1CDDli+7sUy6NEYjwM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=p7kub8zx3LiREgkP8mSwHMu6L9/v8sHI61Z0ox6+LCG1KbCg28PhcXVzFlm1ldvmb K4IuqKmle+MBIyGda6vrubVAuoEfx/9UDXEcJZUqYvQ35etJjZBnpjMgwUzH1JS7ry Dg90aUy+1lipVj3U8KiGAtJWgBOtMEtk+4DVLbzleATFNQS0PO7aqTNGxnSuSuwIpc fYizzId/FQD/JkwjO7q9K5LCRWdhqrnUV1jSlYJTAqrQ1I3Rhu6ovdd14YY6TuhH+w hdAvprVpj2xdxp41avwk0Nh3McGSk2ZNItIvylKyCVYFWx7bSBooCic/YcTM/fv4gL +PizxbdB4BmaQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C61326A07F for ; Mon, 16 Mar 2026 09:48:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676109; bh=K0+/4mIL60n3iOVc8bnHq6EfIzAk+++F4fCtVb4Z70w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WOt1QrKE6HrxcSM1wjw/IlYRj/NsBs7i14k6UoM7DIbb9Je90q5CZTTgXY5W0W4Sw RA6UINg/yKJCMH58KVYC2LDSb3/EkTbH/rmoUPGjyMtmZhteJdSbH1hThPtXQBCZfL CRynytjI399qRH3n+8Cq+tMEgE+uJNvkRErbD7cAwkO7xb1Foc6aiKbSpIOs+9N+b9 8N4bymEVLj5LNzhGVfn1aXh2yVfcUm5s+29L5+mJ0nXbfDxq4zi4Di05Xhy7/NHwoz Bg9Qq7SZLVTfUVVOoy1+FuVFPtkMIxpxWokQ91WA1MUhXAkTgKNP0ilgaTvB/FITNH mXdNHZm2msdgA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DC85F6A07C; Mon, 16 Mar 2026 09:48:29 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id ueqT6OcgV70t; Mon, 16 Mar 2026 09:48:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676109; bh=vPYhdpuug3qznwWvh1Y8NyqxRgr5692bMXwZMMdrcUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmxLBsZR+ZcMomlcVT/qXo+ONX6ydcW7nbZ/sUooAgDy/YnmXmm54wMrIqviAM49S qlqHGf9Dhu1kOVRbMjMF5RisxOeG8cvpdKccv+0tax98jcG9YdaAeygecYUNzEqWgw VGiZCMUB1c0V//Unwsv5iJgoZUwz9F2RHYgBk5JlUmi6veH36V/fIYb7rDsIb41zrY T9UPxuFltmDkMLdIvSuu/ZuHg2KCVMpU/V2OUhtVzr3fP05zRU5l891AfGE/4+2LRy Fzv3PK5ViiFqdo2efTlfnPqtQY2tuUOJnJk1BvzwG3g8U7dy5tTASpPbtcJr7pUp+Q Kl7RaABi8NlMw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 642806A061; Mon, 16 Mar 2026 09:48:29 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 09:47:06 -0600 Message-ID: <20260316154733.1587261-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316154733.1587261-1-sjg@u-boot.org> References: <20260316154733.1587261-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OZEFZYI6M2GEERVRYTBZRJ2JEVNIJBKP X-Message-ID-Hash: OZEFZYI6M2GEERVRYTBZRJ2JEVNIJBKP X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/20] u_boot_pylib: Add stdin_data support to run_pipe() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a stdin_data parameter to run_pipe() so callers can pipe string data to the first command's stdin without needing a temporary file. When stdin_data is provided, stdin is set to PIPE for the subprocess and the data is passed to communicate_filter() as input_buf, which already handles writing to stdin. Signed-off-by: Simon Glass --- tools/u_boot_pylib/command.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/u_boot_pylib/command.py b/tools/u_boot_pylib/command.py index 6b3f9fe59bf..370713bdf41 100644 --- a/tools/u_boot_pylib/command.py +++ b/tools/u_boot_pylib/command.py @@ -66,7 +66,7 @@ class CommandResult: def run_pipe(pipe_list, infile=None, outfile=None, capture=False, capture_stderr=False, oneline=False, raise_on_error=True, cwd=None, - binary=False, output_func=None, **kwargs): + binary=False, output_func=None, stdin_data=None, **kwargs): """ Perform a command pipeline, with optional input/output filenames. @@ -86,6 +86,7 @@ def run_pipe(pipe_list, infile=None, outfile=None, capture=False, binary (bool): True to report binary output, False to use strings output_func (function): Output function to call with each output fragment (if it returns True the function terminates) + stdin_data (str or None): Data to send to the first command's stdin **kwargs: Additional keyword arguments to cros_subprocess.Popen() Returns: CommandResult object @@ -113,6 +114,8 @@ def run_pipe(pipe_list, infile=None, outfile=None, capture=False, kwargs['stdin'] = last_pipe.stdout elif infile: kwargs['stdin'] = open(infile, 'rb') + elif stdin_data: + kwargs['stdin'] = cros_subprocess.PIPE if pipeline or capture: kwargs['stdout'] = cros_subprocess.PIPE elif outfile: @@ -131,8 +134,14 @@ def run_pipe(pipe_list, infile=None, outfile=None, capture=False, return result.to_output(binary) if capture: + if stdin_data and isinstance(stdin_data, str): + input_buf = stdin_data.encode('utf-8') + elif stdin_data: + input_buf = stdin_data + else: + input_buf = b'' result.stdout, result.stderr, result.combined = ( - last_pipe.communicate_filter(output_func)) + last_pipe.communicate_filter(output_func, input_buf)) if result.stdout and oneline: result.output = result.stdout.rstrip(b'\r\n') result.return_code = last_pipe.wait()