1

I want to save the output of a program to a variable.

I use the following approach ,but fail.

$ PIPE RUN TEST | DEFINE/JOB VALUE @SYS$PIPE $ x = f$logical("VALUE")

I got an error:%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters \WORLD\

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

Community
  • 1
  • 1
Y.C.
  • 77
  • 6
  • I'm guessing that the output of the program is more than a single token, i.e. something like "Hello world.". You need to quote the value to get it into a logical name. Not sure of the precise syntax, but probably some variation on `DEFINE/JOB VALUE "''@SYS$PIPE'"`. – HABO Jan 20 '16 at 03:43
  • 1
    `"''@SYS$PIPE'"` will not work: single quoting is for DCL symbols, only. `SYS$PIPE` is a logical and `@` is input redirection. – user2116290 Jan 20 '16 at 08:56

3 Answers3

6

The usual way to do this is to write the output to a file and read from the file and put that into a DCL symbol (or logical). Although not obvious, you can do this with the PIPE command was well:

$ pipe r 2words
hello world
$ pipe r 2words |(read sys$pipe line ; line=""""+line+"""" ; def/job value &line )
$ sh log value
   "VALUE" = "hello world" (LNM$JOB_85AB4440)
$
user2116290
  • 1,062
  • 5
  • 6
1

IF you are able to change the program, add some code to it to write the required values into symbols or logicals (see LIB$ routines)

ChrisB
  • 96
  • 2
0

If you can modify the program, using LIB$SET_SYMBOL in the program defines a DCL symbol (what you are calling a variable) for DCL. That's the cleanest way to do this. If it really needs to be a logical, then there are system calls that define logicals.

Mark Diaz
  • 193
  • 1
  • 10