Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Length Limit When Using SET/P VAR=<\path\file

25 views
Skip to first unread message

pro...@berkeley.edu

unread,
Sep 30, 2016, 6:03:46 PM9/30/16
to
I've been using this for years but never realized (and it doesn't appear to be
documented) that when you read the first line from a file and assign it to a
variable with SET /P myvariable=<\mypath\myfile, the amount of data read seems
to be limited to 1023 bytes. But if one uses

for /f "tokens=*" %X in (\mypath\myfile) do set myvariable=%X

then the entire content of the record will be read (up to the limit of 8192
bytes). Following is copied from my console window (Win7 Pro).

>dir \cmd\data\stat26 | find "stat"
09/29/2016 04:48 PM 3,746 stat26

>reccount \cmd\data\stat26 .
File \cmd\data\stat26 has 1 records.

>set/p _t1=<\cmd\data\stat26

>strlen %_t1%

>set strlen
strlen=1023

>for /f "tokens=*" %X in (\cmd\data\stat26) do @set _t2=%X

>strlen %_t2%

>set strlen
strlen=3743


I didn't do an exhaustive search, but this limit doesn't seem to be documented.
To me, it was a surprise to find that more than half of my record was not being
read with the SET/P method.

Or is this another example of something I once knew but have now forgotten? ;-)

--
Phil Robyn

Tom Del Rosso

unread,
Sep 30, 2016, 6:42:17 PM9/30/16
to
pro...@berkeley.edu wrote:
>
>> set/p _t1=<\cmd\data\stat26

What about this?

type \cmd\data\stat26 | set/p _t1=



pro...@berkeley.edu

unread,
Sep 30, 2016, 11:35:36 PM9/30/16
to
That one gets 'process tried to write to a nonexistent pipe'.

Herbert Kleebauer

unread,
Oct 1, 2016, 4:00:00 AM10/1/16
to
On 01.10.2016 00:03, pro...@berkeley.edu wrote:


> Or is this another example of something I once knew but have now forgotten? ;-)

That's the good (or bad) thing of Google, it never forgets something:

http://www.dostips.com/forum/viewtopic.php?t=2160

Tom Del Rosso

unread,
Oct 1, 2016, 9:13:46 AM10/1/16
to
?
I wonder what's going on there.



pro...@berkeley.edu

unread,
Oct 2, 2016, 2:04:23 AM10/2/16
to
Thanks, Herbert, I am not a frequent visitor of dostips.
0 new messages