How to assign the output of a program to a variable in a DCL com script on VMS?

a 夏天 提交于 2019-11-29 17:09:38

The PIPE command allows you to do Unix-ish pipelining, but DCL is not bash. Getting the output assigned to a symbol is tricky. Each PIPE segment runs in a separate subprocess (like Unix) and there's no way to return a symbol from a subprocess. AFAIK, there's no bash equivalent of assigning stdout to a variable.

The typical approach is to write (redirect) the output to a file and then read it back:

 $ PIPE perl p.pl > temp.txt 
 $ open t temp.txt
 $ read t x
 $ close t

Another approach is to assign the return value as a JOB logical which is shared by all subprocesses. This can be done as a one-liner using PIPE:

 $ PIPE perl p.pl | DEFINE/JOB RET_VALUE @SYS$PIPE
 $ x = f$logical("RET_VALUE")

Since the "RET_VALUE" is shared by all processes in the job, you have to be careful of side-effects.

Look up the PIPE command. It lets you do unix like things.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!