If you have a program that can transform some input text into an alternative output text via a pipe, can you then redirect output of another command to a filename produced by the first program?
echo Hello > source/somedir/somefile.txt | somepipeprogram
The above is probably the wrong syntax, the word Hello ends up in .\source\somedir\somefile.txt even if somepipeprogram
always returns a different filename
I have tested somepipeprogram
and it does indeed correctly transform into my desired output filename
i.e echo \source\somedir\somefile.txt | somepipeprogram
will return my alternate filename.
So if somepipeprogram
was configured to produce 'c:\temp\someotherfilename.txt' from that input, then it would output that using the previous invocation
I thought I had the answer from the following question: https://stackoverflow.com/a/25954264/176690, except the variable that has been set doesn't exist once setvar.bat exits
Here is the contents of my secondary batch file
SETLOCAL
CALL setvar filename echo %1 ^^^^| somepipeprogram
ECHO filename var='%filename%' - if showing var='' expansion failed
I see setvar display the correct answer but the moment it leaves setvar.bat %filename%
does not exist