psh Command

For Windows: Not Supported

The psh BASIC program executes a UNIX command and captures the results in a D3 item. This command is an alternative to the ! command, which allows capturing the result of the UNIX command into a D3 item.

Syntax

psh unix.command {~}>{>} {file} item {(t}

Parameter(s)

unix.command

Any UNIX command. If it contains the > character, it is passed down to sh with its conventional usage. In this case, the > before the D3 item specification must be escaped by a ~ character. Only stdout is captured. To capture stderr, redirect it to stdout.

file

Optional D3 file name where the item is stored. If not specified, lst is used as a default.

item

Item name where the result is stored. If >> are used, with no space in between, the result of the UNIX command is appended to the end of the item, if it already exists.

t

Displays the result on screen, as well as storing it in the specified item.

Example(s)

Prints a calendar for the year 2003 and stores it in the item 2003 in the file tmp.

psh cal 2003 > tmp 2003

Transfers the file /usr/D3/myfile into the D3 item myfile in the file lst (default). If the file does not exist on UNIX, the error message displays on the terminal.

psh cat /usr/D3/myfile > myfile

Transfers the file /usr/D3/myfile into the D3 item myfile in the file lst (default). stderr is redirected to stdout ('2>&1'). Therefore, if the file does not exist, the error message is in the D3 item.

psh cat /usr/D3/myfile 2>&1 ~> myfile

 

NOTE

The escape of the >D3 redirection.

Stores the error messages produced by the two compilations of myprog1.c and myprog2.c in the item myerrs. The second error messages are appended to the end of the first.

psh cc myprog1.c 2>&1 ~> myerrs

psh cc myprog2.c 2>&1 ~>> myerrs

 

NOTE

The escape of the >D3 redirection and the >> to append data.

Changes the directory, lists it, and stores the result in the item mylist.

psh cd /tmp; exec ls -l > mylist

 

NOTE

  • Use exec to avoid creating an intermediate shell.

  • cd is not a UNIX command, but a sh keyword, and thus cannot use the exec command.

See Also

! Command