lundi 13 avril 2015

Can't echo close parenthesis only when piping

I have a pretty peculiar problem, echo writes "ECHO is on." even if it has an argument, but only when printing to a pipe, for certain arguments.


My use case is I'm writing a script file to feed into an interpreter. On Linux I use heredocs to achieve this very nicely.



prog arg1 - arg3 arg4 \
<< EOM
start server load (
foreground
initial database '$database'
directory $directory
from file '${database}.ext'
);
EOM




For Windows' batch I recently discovered something very similar;



(
echo start server load ^(
echo foreground
echo initial database '%%d'
echo directory %directory%
echo from file '%%d.ext'
echo ^);
echo.
) | prog arg1 - arg3 arg4


But I kept getting the following error:



E7511-ACE: '-' line 6: An error has occurred while processing the DDM file.
Caused by
E2420-ACE: Expected punctuation character ')'.
4: directory 'C:\Users\redacted\AppData\Local\Temp'
5: from file 'testing.ext'
6: ECHO is on.
---^---
7: )




But if I instead, begrudgingly, use a temporary file, it all runs fine!



(
echo start server load ^(
echo foreground
echo initial database '%%d'
echo directory %directory%
echo from file '%%d.ext'
echo ^);
echo.
) > tmp.txt
prog arg1 tmp.txt arg3 arg4


Contents of tmp.txt;



start server load (
foreground
initial database 'testing'
directory 'C:\Users\redacted\AppData\Local\Temp'
from file 'testing.ext'
);




I even tried mocking up a .bat to try and show this but all it did was make me think I am crazy



@echo off
set databases=a
for %%d in (%databases%) do (
(
echo bob ^(
echo %%d
echo ^);
)
)
pause


output:



bob (
a
);
Press any key to continue . . .


I don't know any .exes that accept stdin and just write it out to the screen/to a file for me to test my 'it's broken when piping' hypothesis (Windows' type & echo are less versatile than Linux' cat & echo),

do you guys have any ideas?


Aucun commentaire:

Enregistrer un commentaire