How to resolve the algorithm Get system command output step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Get system command output step by step in the Icon and Unicon programming language
Table of Contents
Problem Statement
Execute a system command and get its output into the program. The output may be stored in any kind of collection (array, list, etc.).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Get system command output step by step in the Icon and Unicon programming language
Source code in the icon programming language
#
# 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
You may also check:How to resolve the algorithm Totient function step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Pascal programming language
You may also check:How to resolve the algorithm Mertens function step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Unicode strings step by step in the Phix programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the PicoLisp programming language