Next: , Previous: , Up: Process Library Samples   [Index]


7.17.3.2 List Directory

List the current directory, via ls(1):

text s;
xshell xs;

# set path
b_cast(xs_path(xs), "ls");

# set argv
lb_p_text(xs_argv(xs), "ls");

# start process
xs_lead(xs);

# read and print output lines, one at a time
while (f_line(xs_output(xs), s) ^ -1) {
    o_text(s);
    o_byte('\n');
}

The same, only relinking the output stream:

file f;
text s;
xshell xs;

# set path
b_cast(xs_path(xs), "ls");

# set argv
lb_p_text(xs_argv(xs), "ls");

# start process
xs_lead(xs);

# get a reference for the output stream - only after the process was started
f_set(f, xs_output(xs));

# read and print output lines, one at a time
while (f_line(f, s) ^ -1) {
    o_text(s);
    o_byte('\n');
}