如何在VMS的DCL com脚本中将程序的输出分配给变量? [英] How to assign the output of a program to a variable in a DCL com script on VMS?

查看:82
本文介绍了如何在VMS的DCL com脚本中将程序的输出分配给变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个Perl脚本p.pl,它向标准输出中写入"5".我想将输出分配给这样的变量:

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

推荐答案

PIPE命令允许您执行类Unix的流水线操作,但DCL不是bash.将输出分配给符号很棘手.每个PIPE段都在单独的子进程(如Unix)中运行,并且无法从子进程返回符号. AFAIK,没有将bstout分配给变量的重击.

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

另一种方法是将返回值分配为所有子流程共享的JOB逻辑.可以使用PIPE以单线方式完成此操作:

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")

由于"RET_VALUE"已由作业中的所有进程共享,因此您必须注意副作用.

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

这篇关于如何在VMS的DCL com脚本中将程序的输出分配给变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆