如何将程序的输出分配给 VMS 上 DCL com 脚本中的变量?
例如,我有一个 perl 脚本 p.pl,它将“5”写入标准输出。我想将该输出分配给一个变量,如下所示:
$ x = perl p.pl ! not working code
$ ! now x would be 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PIPE 命令允许您进行 Unix 风格的管道操作,但 DCL 不是 bash。将输出分配给符号是很棘手的。每个 PIPE 段都在单独的子进程(如 Unix)中运行,并且无法从子进程返回符号。 AFAIK,bash 中没有相当于将 stdout 分配给变量的方法。
典型的方法是将输出写入(重定向)到文件,然后将其读回:
另一种方法是将返回值分配为由所有子进程共享的 JOB 逻辑。这可以使用 PIPE 作为单行代码完成:
由于“RET_VALUE”由作业中的所有进程共享,因此您必须小心副作用。
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:
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:
Since the "RET_VALUE" is shared by all processes in the job, you have to be careful of side-effects.
查找 PIPE 命令。它可以让你做类似 Unix 的事情。
Look up the PIPE command. It lets you do unix like things.
我想从文件的 ACL 中识别特定的 ACE,然后将该值分配给我稍后可以在脚本中引用的变量。我想避免写入/读取文件的开销,因为我有数千个文件需要迭代。这个方法对我有用。
$ PIPE DIR/SEC 文件名 |搜索 SYS$PIPE 变量 | (READ SYS$PIPE 变量 &DEFINE/JOB/NOLOG 变量 &变量)
$SHOW LOGICAL 变量
I wanted to identify a particular ACE from a file's ACL and then assign the value to a variable I could refer to later in the script. I wanted to avoid the overhead of writing to/reading from a file as I had 1000s of files to iterate over. This method worked for me.
$ PIPE DIR/SEC filename | SEARCH SYS$PIPE variable | (READ SYS$PIPE variable && DEFINE/JOB/NOLOG variable &variable)
$ SHOW LOGICAL variable