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.
Kind of depends on the format of the data that the device will return. If it
can be configured to append a ctrl-Z at the end of everything to signal an
end-of-file condition, then a copy command might work, i.e.:
copy com1 result.txt
If it returns a fixed number of records, the following might work:
<com1 (set/p line1=&line2=&line3=)
If the extent of the output can be deduced from its content, for example, if
the first line gave the number of lines following, perhaps something like:
<com1 set/p nrec=
for /l %%A in (1,1,%nrec%) do (
<com1 set/p line%%A=
)
If the syntax is more complex, requiring that each line be parsed, well,
that is a little more complex. In that case it might make more sense to
write a program to communicate with the device, or run a scriptable terminal
emulator.
/Al
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:
<nul (set/p z=hello) >out.txt
<nul (set/p z= world!) >>out.txt
dir out.txt
The dir command should indicate the file size as 12 bytes: "hello world!".
The strings output need not be literal, and can originate from any source
capable of creating a variable, simply by including a variable reference in
the prompt string:
<nul (set/p z=sec min hours: %time:~6,2% %time:~3,2% %time:~0,2%)
/Al
Thanks
Clay Calvert
Replace "W" with "L" in email.
Gasp! Al Dunbar finally comes up with something new! Will wonders never
cease?
> Thanks
You're welcome. Enjoy.
/Al
> "Clay Calvert" <ccal...@Wanguru.com> wrote in message
> news:3trs6uon4pej3hci5...@4ax.com...
> > This is an excellent technique. I definitely hadn't seen it before.
>
> Gasp! Al Dunbar finally comes up with something new! Will wonders never
> cease?
>
> > Thanks
>
> You're welcome. Enjoy.
>
> /Al
Great tip, Al! You can also use it to write the 'pesky' characters to a file
(< > | ^ &) if you use double quotes:
<nul (set /p z="<this>|<is>|<only>|<a>|<TEST>")>out.txt
Phil Robyn
Univ. of California, Berkeley
--
u n z i p m y a d d r e s s t o s e n d e - m a i l
Hmmm, I didn't know that set/p would strip the double-quotes before
displaying the prompt. Makes this tip even more useful for the reason you
give.
Now all we need is a similarly simple way to output non-displaying control
characters.
/Al
"Al Dunbar" <Luigi...@hotmail.com> wrote in message
news:eGOMC5AuBHA.2660@tkmsftngp05...