diff options
author | Robby Zambito <contact@robbyzambito.me> | 2021-10-24 01:45:15 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2021-10-24 01:45:15 -0400 |
commit | 98181b833eb4dc6440b73205e64ac010cc4b364c (patch) | |
tree | b8bca1f5177cb09094d098b48ec0a4212de38146 | |
parent | 8d2460e9f61d63dd14ee95784b6f5d1fd1219395 (diff) |
Commands run and print to stdout
-rw-r--r-- | rvsh.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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); |