-1

I need help, i am trying to create a shell in minix3, and i want to create my own "ls" command, so at the moment i am using the execvp command. The only problem is that i would like it to all output on a single line, instead of each directory on their own line. I have been attempting to get this correct for quite some time and i just cant seem to get it right. I am not sure if this is possible or not but any advice on how to achieve the final product without having to use system() would be greatly appreciated!

Example of my Code:

char* arg[] = {"ls", "-1", NULL};
execvp(arg[0], arg);

Thank you in advanced!

MyGGaN
  • 1,766
  • 3
  • 30
  • 41

1 Answers1

0

The easiest is probably to pipe the output of ls to tr. You could use complicated code to set up pipelines, or you could invoke sh with a script instead:

char const* args[] = {"sh", "-c", "ls | tr '\n' ' '", NULL};
execvp(args[0], args);

Or if you're fine with commas between the entries, pass the -m flag to ls:

char const* args[] = {"ls", "-m", NULL};
execvp(args[0], args);