Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dos Batches: write to files without a line ending

I have a situation while writing a dos batchs script. A tool I am using to calculate CRC (checksum) of a text string requires the text to be in a file. The data I am trying to get the CRC for is a filename, but when using a batch to put this filename into a text file to calculate CRC, the batch script naturally puts the line ending (CR/LF) and a blank line at the end. As this causes the CRC to be wrong, it is a problem.

Is there any way to get a batch script to write to a text file without appending a line ending? IE to output a single line unfinished to file?

-K.Barad

like image 784
K.Barad Avatar asked Feb 28 '12 11:02

K.Barad


2 Answers

<nul set /p ".=text" > file

It's faster and safer than echo.|set /P ="text" > file

The nul redirection is faster than a pipe with echo. (btw echo.can fail).
The style of the quotes allowes to output also quotes.

But there are always restrictions!
Vista and Win7 have a "feature" to supress leading spaces, Tabs and CR's.
Xp can output text with leading spaces and so.
And it's not possible to begin the output text with an equal sign (results in a syntax error)

like image 148
jeb Avatar answered Nov 02 '22 23:11

jeb


You could

echo.|set /P ="text" > file

source

Or directly pipe the text to the command line: echo "text" | checksum_program.exe

edit:

if you're using CRC32DOS, then you can use its command line option -c to ignore CRs.

like image 37
vulkanino Avatar answered Nov 03 '22 00:11

vulkanino