Chapter 7 287
Integrating Programs In Other Languages
Using a System Command
Lab 7-2: Listing the Files in a Directory (UNIX)
In this exercise, you will use the operating system command ls, which lists
the filenames in a directory. Since this is not a shell-dependent command,
you can set Shell to
none. Then you will program a variation of this exercise
using a shell-dependent feature, the pipe (
|).
To list the files in an HP-UX program, use the
ls command as follows.
1. Select
I/O ⇒ Execute Program (UNIX) and place it in the
upper-left work area.
2. Make sure the
Shell field is set to none and the Wait for prog exit
field is set to
Yes. This ensures the ls command terminates before VEE
continues with the program.
3. Click the
Prog with params field and enter: ls /tmp. (You could
specify any directory.)
4. Add a data output terminal. The default will be named
X. There is no exit
code from the program, so disregard the terminal labeled
Exit code.
5. Double-click the transaction bar to get the
I/O Transaction box. Edit
the default variable a to an
X, since data from the program will be read
into that output terminal.
a. Change
WRITE to READ, to specify a READ TEXT transaction.
b. Change
REAL64 FORMAT to STRING FORMAT.
c. Change the shape of the data from
SCALAR to ARRAY 1D, to specify a
one-dimensional array.
d. Toggle the
SIZE: button to TO END: (*), since you do not know
how many files are in the directory. Click
OK. The transaction bar
should now read
READ TEXT X STR ARRAY:*.
6. Select
Display ⇒ Logging AlphaNumeric and connect its data
input pin to the
X terminal on the Execute Program object.