0

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

Community
  • 1
  • 1
Peter Nimmo
  • 1,045
  • 2
  • 12
  • 25
  • At the moment I have solved my problem by moving the techniques from setcmdvar directly into the script, its not re-usable but it does work – Peter Nimmo Dec 15 '16 at 11:32

1 Answers1

0

echo Hello > somepipeprogram

or

echo Hello > $( somepipeprogram )

also depending or your shell.

(I am obviously assuming some Unixy shell like bash here.)