I knew the command which actually worked here is technically incorrect. OTOH your error message is missing the information - which program detected the error? Was it TCC, CMD, or tr?
BTW, this the command:
echo foo | tr "o" "\"" >foo.txt
reported in CMD:
tr: too many arguments
Try `tr --help' for more information.
The process tried to write to a nonexistent pipe.
The same command in TCC reported the first two lines (with full path for tr), but not the third line. No empty file was created by either command processor.
I suspect that both the CMD and TCC parsers get mixed up on "\"" - is the backslash your TCC escape character? It is not mine...
I discovered that TCC escape sequences, such as %=q, do not work inside quoted strings - seems the quotation marks surrounding the string allow translation of the %= to my chosen escape character (which is ctrl-X as in 4DOS), but the second translation of the sequence [EscapeChar]q into a quotation mark does not take place.
BTW, the same issues occur in
tr "o" "\"" > foo.txt
(which expects the word "foo" from the keyboard) without the left side of the pipe, the issue is not related to piping. It definitely is related to redirection.
The simple command
echo %@replace[o,%=q,foo] > foo.txt
works, but add another o into the source string:
echo %@replace[o,%=q,foorox] > foo.txt
and it gets confused, and instead of redirection, displays
f""r"x > foo.txt