When executing external commands (cat, etc.) with pipes, the command output was not properly redirected to the pipe.
crash> cat /tmp/testfile line1 line2 line3 crash> cat /tmp/testfile | head -1 line1 line2 line3 crash> Signed-off-by: neilfsun <[email protected]> Signed-off-by: Feng Sun <[email protected]> --- main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 71bcc15..95d455a 100644 --- a/main.c +++ b/main.c @@ -1034,6 +1034,8 @@ is_external_command(void) int i; char *cmd; char command[BUFSIZE]; + FILE *pipe; + char buf[BUFSIZE]; cmd = args[0]; @@ -1057,8 +1059,19 @@ is_external_command(void) else strcat(command, args[i]); } - if (system(command) == -1) - perror(command); + + if (pc->redirect & REDIRECT_TO_PIPE) { + if ((pipe = popen(command, "r")) == NULL) { + error(INFO, "cannot execute: %s\n", command); + return TRUE; + } + while (fgets(buf, BUFSIZE, pipe)) + fputs(buf, fp); + pclose(pipe); + } else { + if (system(command) == -1) + perror(command); + } return TRUE; } -- 2.50.1 -- Crash-utility mailing list -- [email protected] To unsubscribe send an email to [email protected] https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/ Contribution Guidelines: https://github.com/crash-utility/crash/wiki
