I have a pipeline that may produce output I want to replace an existing
file with.
If the pipeline doesn't produce any output, I don't want to erase the
existing file.

Example: PIPE ... | > SOME FILE A
if there's no data on > primary input, SOME FILE A is erased (or emptied)
and it's clearly documented that way.

I'm looking for something like
PIPE ... | > CONDITIONAL SOME FILE A
Now, > (and family) doesn't open the output file until it gets the first
record on primary input. No input? The file is not opened, and the existing
file is left as-is.

This should work... I'll try it ...
PIPE ... | STRLITERAL CONDITIONAL /CALLPIPE *: || > SOME FILE A/ | PIPCMD

Or, I could do something more procedural than pipe-think, like:
'PIPE ... | > NEW FILE A'
'ESTATE NEW FILE A '
if 0 = rc then do
   'ERASE SOME FILE A'
   'RENAME NEW FILE A SOME = ='
'end'

but > CONDITIONAL is so much more elegant. :-)
And it can't be confused as a file name, so it's unambiguous. :-)

Reply via email to