From afc4ba3d060a8e7320e8beeef46a9bc7b525be76 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Wed, 27 Aug 2025 14:50:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20`xy=5Frun=5Fget=5Fstatus()?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/xy.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/xy.h b/lib/xy.h index 3dd9c38..68f7340 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -839,11 +839,25 @@ xy_run (const char *cmd, unsigned long n) } +/** + * @brief 执行命令,仅返回命令的执行状态 + */ +int +xy_run_get_status (char *cmd) +{ + char * command = xy_str_to_quietcmd (cmd); + + int status = system (command); + return status; +} + + /** * @brief 捕获命令的输出 * * @param[in] cmd 要执行的命令 - * @param[out] output 捕获的标准输出 + * @param[out] output 捕获的标准输出, + * 为NULL时表示不关心stdout输出,但依然允许stderr输出 * * @return 返回命令的执行状态 */ @@ -874,8 +888,11 @@ xy_run_capture (const char *cmd, char **output) buf[size] = '\0'; int status = pclose (stream); - *output = buf; - return status; + + if (output) + *output = buf; + + return status; }