From 98181b833eb4dc6440b73205e64ac010cc4b364c Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 24 Oct 2021 01:45:15 -0400 Subject: Commands run and print to stdout --- rvsh.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rvsh.c b/rvsh.c index db2ddd5..211f3a0 100644 --- a/rvsh.c +++ b/rvsh.c @@ -127,6 +127,8 @@ void run_reverse_command(char *command) { pid_t bash_pid; union pipe bash_input, bash_output; FILE *bash_input_f, *bash_output_f; + char *line; + size_t line_capacity; pipe(bash_input.filedes); pipe(bash_output.filedes); @@ -153,7 +155,14 @@ void run_reverse_command(char *command) { bash_input_f = fdopen(bash_input.write_end, "w"); bash_output_f = fdopen(bash_output.read_end, "r"); - put_stream_rev(bash_output_f); + line = NULL; + line_capacity = 0; + while (getline(&line, &line_capacity, bash_output_f) > 0) { + strrev(line); + printf("%s", line); + } + + free(line); fclose(bash_input_f); fclose(bash_output_f); @@ -168,7 +177,6 @@ int main(void) { add_history(line); strrev(line); - /*puts(line);*/ run_reverse_command(line); -- cgit v1.2.3