Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Riddle: How to echo > into a file?

Dec
73
1
I've got some strings containing < and > located in strings and would like to echo-redirect them into a file (encoded as latin, not utf16 as filewrite seems to insist to do):

setdos /x-6
set sting=test1<test2>test3
setdos /x+6
echo %string > file.txt

This doesn't work, the < and > inside the variable get interpreted as redirection. Is there any way to do this? Thanks!
 
Code:
@setlocal
@echo off
plugin /l safechars.dll
setdos /x-6
set string=test1<test2>test3
setdos /x+6
echo %@safeenv[string] > file.txt
type file.txt
plugin /u safechars
endlocal

Visit http://prospero.unm.edu/dl/safechars.zip to download the safechars plugin.

Joe
 
You can try with the %@filewrite[…] category of functions.

Wellyes, as written in the op I'd like non-unicode output, and filewrite generates utf16 - so I'd need another xcode command to convert it.

Code:
rem or use setdos /x-6
set string=test1^<test2^>test3
set string > file.txt

Did you actually try this :-) ... doesn't work because the redirector is disabled by setdos, that's the whole point!

Visit http://prospero.unm.edu/dl/safechars.zip to download the safechars plugin

Thanks, I'll probably go for this. I already had a look before and the approach (same for html) seems a bit hack-ish as you need to disable utf output. But alas, due to the dodgy handling of utf8 by tcc I went the old-school latin way now anyway.
 
If you don't have any percent signs on the command line, then no variable expansion is done:
Code:
set string=`test1<test2>test3`
set string > file.txt
 
Did you actually try this :-) ... doesn't work because the redirector is disabled by setdos, that's the whole point!
Of course I tried it. When I don't I usually add "(untested)" to the code in my replies. Did you notice that the first lin my code block is a comment and not a setdos command? The solution I gave you is equivalent to Charles' - there's only a difference in how > is escaped, ^ vs backquote.
 

Similar threads

Back
Top