"john miller" <jo...@millertransportation.com> wrote in message news:43ea01c1b558$aa1d7010$19ef2ecf@tkmsftngxa01... > I have a device attached to COM1 which sends/recieves > data. I have been able to send data using this: > > echo "command" > COM1 > > How can I recieve the answer or result that the device is > returning. I would like for the for the data which is > being transmitted from the device to go to a file.
In testing my previous reply to the above, I ran across a way to simulate an ECHO without a terminating CRLF sequence using batch-only facilities. No doubt others are aware of this, however, I have not seen it since I have been following this newsgroup, so will post it here for the benefit of any others who, like myself, did not know.
The command "echo.hello world" emits the string "hello world" followed by a CRLF sequence. There are at least a couple of situations where this fact is a nuisance:
- displaying a minimalist progress bar. - sending arbitrary character strings to a serial device. - writing strings from separate commands that need to appear in the same line in an output file.
The command that does this is:
<nul (set/p anyvariable=string to emit)
The "<nul" pipes a nul response to the set/p command, which will cause the variable used to remain unchanged. As usual with set/p, the string to the right of the equal sign is displayed as a prompt with no CRLF.
Here is an example where this is used for a rudimentary progress bar:
@echo off for /l %%A in (1,1,20) do ( <nul (set/p z=%%A) >nul ping 127.0.0.1 -n 2 )
And here is an example where info is written to a single line in a file from multiple uses of the set/p command: