Task
Execute a system command and get its output into the program. The output may be stored in any kind of collection (array, list, etc.).




Related task
  Execute a system command


#
# piped.icn, Get system command output
#
# Dedicated to the public domain
#
procedure main()
    # start with an empty list
    directory := []
 
    # ls for UNIX, dir for other, assume Windows
    command := if &features == "UNIX" then "ls" else "dir"
 
    # open command in pipe mode
    p := open(command, "p") | stop("Cannot open pipe for ", command)
 
    # read in results and append to list
    while put(directory, read(p))
 
    # display the fifth entry, if there is one
    write(\directory[5])
 
    close(p)
end