Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Pipe result to DCL symbol

SOLVED
Go to solution
Aaron Lewis_1
Frequent Advisor

Pipe result to DCL symbol

I am trying to get the result of a piped search command directly to a symbol.

sea file.txt/noout/stat|sea sys$input matched

I would like to get the number of hits from the seach directly into a symbol without writting a temp file, and reading it back in.
7 REPLIES
Volker Halle
Honored Contributor

Re: Pipe result to DCL symbol

Aaron,

you can't directly put the result into a symbol from PIPE, as the piped commands run in subprocesses and you can't pass a symbol back from a subprocess. You need to use a logical as a workaround.

here is an example:

$ pipe sea login.com/noout/stat x |search sys$pipe matched| ( read sys$pipe x ; y=F$ELEMENT(2," ",F$EDIT(x,"TRIM,COMPRESS"))
$ count = F$TRNLNM("COUNT")
$ sho sym count
COUNT = "18"
$ deass/job count

Volker.
Joseph Huber_1
Honored Contributor

Re: Pipe result to DCL symbol

First of all , using a pipe, You can't bring back a symbol to the master process, You have to define a JOB-logical name.
To do that for the search statistics, write a DCL command-file, which basically does:
$ line = ""
$loop:
$read/end=done sys$pipe line
$if f$extract(0,16,line).eqs."Records matched:" then goto done
$goto loop
$done:
$ define/job myresult "''line"
$ exit
$! or extract the matched number from line and define that in logical name.

Then call it like:
$PIPE search/stat/window=0 myfile mystring | @commandfile
$mysymbol=f$trnlnm(myresult)
$deass/job myresult
$if mysymbol.eqs."" then goto errorhandling
...
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: Pipe result to DCL symbol

Well Volker was faster, and his one-liner is more compact,
but add at the end of the pipe command:
; define/job count &y)
to make it complete.

And in general, use a command-file in a pipe
to define a logical, if You expect something different than a number or a single "word":
the content of &y must be a legal parameter 2
(and no more) for the define command.
Therefore parse and make sure it is legal (by simply enclosing it in "" quotes.
http://www.mpp.mpg.de/~huber
Volker Halle
Honored Contributor

Re: Pipe result to DCL symbol

Joseph,

thanks for the correction. It worked on my OpenVMS system, so the rest of the command line must have got lost in the cut & paste exercise ;-(

Volker.
Hein van den Heuvel
Honored Contributor

Re: Pipe result to DCL symbol


Volkers solution appears to miss the DEFINE/JOB in the sub shell.

I tried a few times, but failed to add that readily in the onle liner, notably because command line editing gets nasty after 132 chars or so.

I would suggest you check out PERL.
This give you regular expressions to boot!
It can solve the problem in the same process with a single image activation:

$ cre tmp.tmp
aap
getjpi
noot
GETJPI
mies
$
$ perl -ne "$ENV{COUNT}=++$match if (/getjpi/i)" < tmp.tmp
$
$ show log count
"COUNT" = "2" (LNM$PROCESS_TABLE)


-n = loop though sys$input
-e = immediate program text follows
< = take sys$input from specified file

%ENV is an associative array magically mapped onto logical name spaces (and more!)

/getjpi/ is the match string I happen to have used.
/getjpi/i makes it case insensitive


fwiw,
Hein.
Volker Halle
Honored Contributor
Solution

Re: Pipe result to DCL symbol

Now here is the correct 1-liner (with continuation lines to fit into this ITRC thread frame):

$ pipe sea login.com/noout/stat x |search sys$pipe matched| ( -
_$ read sys$pipe x ; y=F$ELEMENT(2," ",F$EDIT(x,"TRIM,COMPRESS")) -
_$ ; def/job count &y )

$ sho log count
"COUNT" = "18" (LNM$JOB_821A4BC0)

Volker.
Aaron Lewis_1
Frequent Advisor

Re: Pipe result to DCL symbol

The pipe command is working