1.

Solve : How to escape | < > in a batch file.?

Answer»

Hey, I was just wondering how, when entering a value into a batch file you can automatically 'escape' out the characters that usually make the program close. "| < >".

I've tried set x=%x:^|=^^^|% though it doesn't work.

For example, how would I make this code work?

Quote

@echo off

set /p in=Input "|":
echo %in%>dump.txt

If the input was "|", how would I make it so "|" and only "|" is outputted to the file. No quotation marks either, I think they work?Escape the variable as if it were the character it would expand to.

Quote

@echo off
set /p in=Input "|":
echo ^%in% > show.txt
type show.txt
pause


Quote

Input "|":|
|
Press any KEY to continue . . .


Yea, I probably didn't phrase the question properly.

What if the variable included "< > |" anywhere inside it, eg "dksk>>|", for example.

How would you enable that to be used by an if, echo or other command, without causing an error and EXITING?Quite honestly, DeltaSlaya, this is where I say to myself, "here be the limitations of command LINE" and DIG out QBasic. Life is too short.

Ok, so it's just not possible? I thought that ":str1=str2" could work, I'm guessing it can't, and I haven't got it to work with it either.You did know you can make a batch file create and execute a Qbasic program?

echo FOR J=1 TO 10 > dome.bas
echo PRINT J >> dome.bas
echo NEXT J >> dome.bas
qbasic /run dome.bas

Thus you could for example get a string input and get it into a file by passing the string to a QBasic program to do the file creation and writing. You'd have to be sure QB was present on the system, which up to Win ME, you were.





@OP,
if QBasic is not present on the system (which newer windows OS doesn't come with it), then the next best thing after DOS is vbscript (considering native requirement). Quote from: ghostdog74 on AUGUST 07, 2007, 05:51:48 AM
@OP,
if QBasic is not present on the system (which newer windows OS doesn't come with it), then the next best thing after DOS is vbscript (considering native requirement).

Now, how did I know you were going to write that?

Next best? Vbscript is way better than QBasic.


Discussion

No Comment Found