Skip to content

Commit afc4ba3

Browse files
committed
添加 xy_run_get_status()
1 parent 4cffe05 commit afc4ba3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/xy.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,25 @@ xy_run (const char *cmd, unsigned long n)
839839
}
840840

841841

842+
/**
843+
* @brief 执行命令,仅返回命令的执行状态
844+
*/
845+
int
846+
xy_run_get_status (char *cmd)
847+
{
848+
char * command = xy_str_to_quietcmd (cmd);
849+
850+
int status = system (command);
851+
return status;
852+
}
853+
854+
842855
/**
843856
* @brief 捕获命令的输出
844857
*
845858
* @param[in] cmd 要执行的命令
846-
* @param[out] output 捕获的标准输出
859+
* @param[out] output 捕获的标准输出,
860+
* 为NULL时表示不关心stdout输出,但依然允许stderr输出
847861
*
848862
* @return 返回命令的执行状态
849863
*/
@@ -874,8 +888,11 @@ xy_run_capture (const char *cmd, char **output)
874888
buf[size] = '\0';
875889

876890
int status = pclose (stream);
877-
*output = buf;
878-
return status;
891+
892+
if (output)
893+
*output = buf;
894+
895+
return status;
879896
}
880897

881898

0 commit comments

Comments
 (0)