This may be a bit confusing.
I want to create a batch file that creates another batch file, which finally creates another file. Such as the example code below:
echo echo hi > output.txt > newbatch.bat
I colored the code for you. The point is that this program creates another program called newbatch.bat, which when opened creates a text file called output.txt with the file consisting of 'hi'. But when I run this code, it actually creates TWO files, I have tried everything there was to fix this, from quotation marks, all the way to more than one of >.
Advanced Thanks.
Double > in Batch File
Moderator: DosItHelp
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: Double > in Batch File
Very good! Are all the 'special characters' ignored when placed? (not including for the % of course). And what exactly does 'Escape special characters' mean?
Re: Double > in Batch File
A special character is > < & | and several others.
When they are 'escaped' with a ^ character then they can be echoed into a file.
Some characters are very difficult to deal with in batch scripts with " being a good example.
And from a command line there are issues with , = ; and others.
Alpha and numeric characters are in general ok but you will also find difficulties with foreign language characters and a command prompt.
And with delayed expansion ! becomes a problem character.
Welcome to batch files and weird and wonderful exceptions...
When they are 'escaped' with a ^ character then they can be echoed into a file.
Some characters are very difficult to deal with in batch scripts with " being a good example.
And from a command line there are issues with , = ; and others.
Alpha and numeric characters are in general ok but you will also find difficulties with foreign language characters and a command prompt.
And with delayed expansion ! becomes a problem character.
Welcome to batch files and weird and wonderful exceptions...
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: Double > in Batch File
Thanks. I was a newbie; for months I thought that DOS was namely called batch, so therefore I found no forum. You have taught me. And therefore I thank you all.
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: Double > in Batch File
You said some characters are very difficult to deal with in batch scripts with " being a good example. Could you please expand this further? Why is that hard to deal with, and WHEN is it 'hard to deal with'?
In command lines there are issues with , = ; and what are the issues to this? What are the problems? That's it for now, thanks.
In command lines there are issues with , = ; and what are the issues to this? What are the problems? That's it for now, thanks.
Re: Double > in Batch File
Filenames are double quoted all the time as in "This is an exe filename.exe" when including spaces etc.
But if you are parsing a text file and it has a line like this
"&ten books"and"thirteen spades&"
then it can be difficult to extract parts of the string, character by character. The presence of the & character means you need double quotes to handle the poison & character and using double quotes to process a double quote is a problem.
This isn't very clear but when you have a double quoted line and it has a double quote in the middle of it, and you need to manipulate the string, then it is an issue.
The other question has to do with calling a subroutine or a batch file from the command line.
If you try this batch file you will see that = , ; become invisible.
mybat "one & two" = "two & one" , three ; four
But they will be preserved inside double quotes.
mybat "one = two" "two = one" "three ; four"
The same thing happens when calling a label inside a batch file.
But if you are parsing a text file and it has a line like this
"&ten books"and"thirteen spades&"
then it can be difficult to extract parts of the string, character by character. The presence of the & character means you need double quotes to handle the poison & character and using double quotes to process a double quote is a problem.
This isn't very clear but when you have a double quoted line and it has a double quote in the middle of it, and you need to manipulate the string, then it is an issue.
The other question has to do with calling a subroutine or a batch file from the command line.
If you try this batch file you will see that = , ; become invisible.
mybat "one & two" = "two & one" , three ; four
Code: Select all
:: mybat.bat
@echo off
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
e:\>mybat "one & two" = "two & one" , three ; four
"one & two" "two & one" three four
But they will be preserved inside double quotes.
mybat "one = two" "two = one" "three ; four"
e:\>mybat "one = two" "two = one" "three ; four"
"one = two" "two = one" "three ; four"
The same thing happens when calling a label inside a batch file.