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

Deadly 提交于 2019-11-28 10:38:40

问题


For example, I have a perl script p.pl that writes "5" to stdout. I'd like to assign that output to a variable like so:

$ x = perl p.pl ! not working code
$ ! now x would be 5

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4431757/how-to-assign-the-output-of-a-program-to-a-variable-in-a-dcl-com-script-on-vms

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