Special character is befuddling my batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Special character is befuddling my batch file

#1 Post by mjfoxtrot » 04 Dec 2014 04:43

I produce HTML pages for my web site using various batch files. For some reason on the bottom of several pages, there is a special character (at least, that is what it seems to be to me) that looks like a thin line with a small arrow pointing to the right. I would paste the character on this post, but it doesn't copy into this window. On some text editors, the character appears as "^Z", minus the quotation marks.

I believe the character is a line feed break, or a new line delimiter of some kind, because the effect it has on my web pages is to add a blank line at the bottom of the page. The character can be deleted easily enough by hand, but when I try to remove it using any of the command-line search-and-replace batch tools I use, the command line argument halts as soon as the special character is encountered. To be more clear, this is the command line argument (the character is represented in the command line by the "+" symbol, and you can see it toward the end of the CL argument)

"C:\Programs\fnr\fnr.exe" --cl --silent --dir "C:\macros\trades\html" --fileMask "*.html" --excludeFileMask "*.dll, *.exe" --caseSensitive --find "+" --replace ""

I'm basically trying to remove the special character and replace it with nothing; in effect, deleting it altogether. But, I can't do it, because the CL argument stops as soon as the special character occurs. I believe the character has the same effect as hitting the enter key, because the error message I get is this:

" --replace "" is not recognized as an external or internal command.

Those are the words right after the special character, so obviously the character has stopped the CL program dead in its tracks and tries to continue on with a perceived command that is nothing more than a fragment of the command line argument.

I've tried using an escape character, namely, ^, to try and stop the command prompt from interpreting the character as a special command, but I've not had any luck.

Any thoughts on what I can do to make the command line argument work in this case? I would think there would be some way that I could make the special character be perceived in the command window as a regular character, but so far I'm at a loss.

Thanks in advance for any help.

miskox
Posts: 352
Joined: 28 Jun 2010 03:46

Re: Special character is befuddling my batch file

#2 Post by miskox » 04 Dec 2014 05:40

^Z is an EOF character. This might help:

viewtopic.php?p=32468#p32468

Code: Select all

copy /a file.txt out_file.txt /b


Saso

Squashman
Expert
Posts: 4178
Joined: 23 Dec 2011 13:59

Re: Special character is befuddling my batch file

#3 Post by Squashman » 04 Dec 2014 06:23

Would help to see your batch file. We really can't tell you why it is happening without seeing it. We are not omniscient but this topic has been covered on the forums in the past.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Special character is befuddling my batch file

#4 Post by foxidrive » 04 Dec 2014 07:23

The control Z is often appended by a copy command.

Assuming you have control of the batch file then you can use binary mode with the copy command by adding the /B switch and the ^Z/EOF character will not be added.

mjfoxtrot
Posts: 23
Joined: 02 Jun 2014 19:03

Re: Special character is befuddling my batch file

#5 Post by mjfoxtrot » 04 Dec 2014 11:48

Yep, problem solved. As usual, you guys provided me the necessary insight to solve the problem almost instantly. The problem was with a comspec command that I was using in a VBA script to build my web pages. For instance, the comspec line that I had been using was this, which basically merged together several text files into an .HMTL page:

Shell Environ$("COMSPEC") & " /c Copy C:\macros\trades\html\*.txt C:\macros\trades\html\transactions.html "

That turned out to be what was adding the EOF character. So, thanks to the suggestions by foxidrive and miskox, I simply added the binary mode switch (/b) to the comspec line, like so:

Shell Environ$("COMSPEC") & " /c Copy C:\macros\trades\html\*.txt /b C:\macros\trades\html\transactions.html "

. . . and the problem is completely solved. No more EOF character any more.

Squashman, sorry to have not posted the entire batch file. For simplicity's sake, I was trying to isolate the problem on one particular line of code, and as it turned out, the code that I provided was not where the problem existed. So your point is well-taken about posting the file in its entirety.

Thanks again to all of you for taking the time to address - and solve - my issue.

Post Reply