MSFN Forum: How to get around the 2047 characters CMD string limitation - MSFN Forum

Jump to content


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How to get around the 2047 characters CMD string limitation Rate Topic: -----

#21 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 08 March 2013 - 12:11 AM

That's why I use date.exe from UnxUtils.


#22 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,737
  • Joined: 13-January 06

Posted 08 March 2013 - 01:04 AM

I do the same most of the time.

#23 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 08 March 2013 - 06:39 AM

Well, for the record, there is a "way out" without third party tools, using WMI time classes (on XP, NOT on 2K, which misses a few classes).
http://technet.micro...y/ee198928.aspx
http://msdn.microsof...0(v=vs.85).aspx

What is available should be:

Quote

Windows 2000
Win32_TimeZone
Win32_SystemTimeZone

Windows XP
Win32_TimeZone
Win32_SystemTimeZone
Win32_UTCTime
Win32_CurrentTime
Win32_LocalTime


For 2K (but also for XP if one wants to have the date/time format in the "full" UTC format), writing a file and immediately get it's created or last accessed time/date may be a good enough workaround :unsure:.


jaclaz

#24 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,082
  • Joined: 12-May 07

Posted 11 March 2013 - 12:35 AM

AFAIK, here is a way to get the current date and time using batch/CMD script that will return a consistently formatted string in any version of Windows from WinXP through Win8 and 2012, (I believe it should also work in Win2K but I would appreciate someone validating that), where the OS is either 32-bit or 64-bit, in any language, in any locale, even if the date/time separators have been modified by the user.

Date:
Spoiler


Time:

Spoiler


Cheers and Regards

#25 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 11 March 2013 - 03:27 AM

View Postbphlpt, on 11 March 2013 - 12:35 AM, said:

AFAIK, here is a way to get the current date and time using batch/CMD script that will return a consistently formatted string in any version of Windows from WinXP through Win8 and 2012, (I believe it should also work in Win2K but I would appreciate someone validating that), where the OS is either 32-bit or 64-bit, in any language, in any locale, even if the date/time separators have been modified by the user.

They must be VERY different from the ones in the link I gave in post #19 :whistle:
http://www.msfn.org/...ost__p__1032424

Seriously :), what are the changes (improvements) when compared against the "official" SORTDATE/SORTTIME? (which are already "certified" to be working also on NT 4 and 2K)
Nesting the IF's with IF/ELSE? :blink:

jaclaz

This post has been edited by jaclaz: 11 March 2013 - 03:27 AM


#26 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,082
  • Joined: 12-May 07

Posted 11 March 2013 - 09:25 AM

I came up with both of those about 2 and a half years ago. For Date, you are correct that the core of the code is essentially a reformatting of Rob's SortDate Version 3.10, which is why he is given specific credit, with the only change really being in the added output of the individual components in addition to the combined date string. (I never really saw the advantage of Rob's Version 4 of SortDate.) Time did not come from any version of Rob's SortTime code at all. (The core code for it came from ss64.com as credited, including the comment about the guy with green ink. LOL) I guess really the shortest solution to get both date and time is Rob's SortDate Version 5.

Cheers and Regards

This post has been edited by bphlpt: 11 March 2013 - 09:26 AM


#27 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 11 March 2013 - 10:38 AM

View Postbphlpt, on 11 March 2013 - 09:25 AM, said:

I guess really the shortest solution to get both date and time is Rob's SortDate Version 5.

Yep :), but that, as already posted, only applies to XP and later.

The shortest version (in XP) is using the WMIC approach, the shortest for 2K (as I see it) is something *like*:
@ECHO OFF
SETLOCAL
cd.>datefile.$
FOR /F "tokens=1,2 delims= " %%A IN ('dir datefile.$ ^| FIND "datefile.$"') DO SET my_date=%%A & SET my_time=%%B
del datefile.$
set my_

but it misses seconds (and of course it is only useful to get rid of the "day of the week feature").

What could also work on 2K (haven't a test bed handy, so needs to be checked/tested) may be variable expansion:
 @ECHO OFF
SETLOCAL ENABLEEXTENSIONS
cd.>datefile.$
Call :do_date datefile.$
GOTO :EOF
:do_date
FOR /F "tokens=1,2 delims= " %%A IN ("%~t1") DO SET my_date=%%A & SET my_time=%%B
del datefile.$
set my_


jaclaz

#28 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,737
  • Joined: 13-January 06

Posted 11 March 2013 - 02:33 PM

The great advantage of unix tools date is that you get easily and without hassle the date / time in almost whatever format you might imagine.

#29 User is offline   blackwingcat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 579
  • Joined: 31-May 08
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 11 March 2013 - 08:01 PM

And another difference.

2000 + CMD.exe(2000)
Microsoft Windows 2000 [Version5.0.2195]

2000 + CMD.exe(XP)
Microsoft Windows XP [Version5.0.2195]

XP + CMD.exe(XP)
Microsoft Windows XP [Version5.1.2600]

#30 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 12 March 2013 - 03:40 AM

View Postallen2, on 11 March 2013 - 02:33 PM, said:

The great advantage of unix tools date is that you get easily and without hassle the date / time in almost whatever format you might imagine.

Yep, but the point (mine) was to not use external programs.
There is also a debug script, that should work on 2K as well:
http://www.robvander...e.com/debug.php
Now, Today and Todaynow

jaclaz

#31 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,737
  • Joined: 13-January 06

Posted 12 March 2013 - 03:37 PM

Never needed to use this means but if you go this way then you could also use something like the method used by Herbert Kleebauer there or like explained there to put any needed executable in the batch as some resource that would be extracted/decoded before being used.

#32 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 13 March 2013 - 04:45 AM

View Postallen2, on 12 March 2013 - 03:37 PM, said:

Never needed to use this means but if you go this way then you could also use something like the method used by Herbert Kleebauer there or like explained there to put any needed executable in the batch as some resource that would be extracted/decoded before being used.

Yes, of course :thumbup , though I personally tend to to use the simpler ECHOO.COM (also by Herbert Kleebauer):
http://reboot.pro/to...closed/?p=21795
for the little uses I need (which are usually connected to "dynamically produce some hex bytes).

I am really "old school" :ph34r: but I really see no issues in having an external tool and - whenever possible/advisable - I try not to "embed" anything inside "anything else", in which case the so-called "batch compilers" (which mostly - but not all ) do nothing but package the batch and the needed tools into a SFX archive, seem to me a better choice.

jaclaz

#33 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 17 April 2013 - 09:12 AM

View Postjaclaz, on 08 March 2013 - 06:39 AM, said:

For 2K (but also for XP if one wants to have the date/time format in the "full" UTC format), writing a file and immediately get it's created or last accessed time/date may be a good enough workaround :unsure:.

How about this as a workaround?

CD.>temp
cabarc n temp._ temp
FOR /F "skip=9 tokens=3-8 delims=/: " %%A IN ('cabarc l temp._') DO ECHO %%A%%B%%C.%%D%%E%%F


The result is same as using

date.exe +%%Y%%m%%d.%%H%%M%%S


#34 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 17 April 2013 - 09:45 AM

View Posttomasz86, on 17 April 2013 - 09:12 AM, said:

How about this as a workaround?

Which advantage has it when compared to the snippet in post #27 (that needs not cabarc or *any* external program)? :unsure:

The issue is that you need to create a file (in your case TWO of them).

jaclaz

#35 User is offline   tomasz86 

  • http://www.windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,220
  • Joined: 27-November 10
  • OS:Windows 2000 Professional
  • Country: Country Flag

Posted 17 April 2013 - 11:01 AM

The advantage is that you also get seconds and that it's completely locale independent (you get hours in the 24-hour format).

#36 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 17 April 2013 - 12:25 PM

View Posttomasz86, on 17 April 2013 - 11:01 AM, said:

The advantage is that you also get seconds and that it's completely locale independent (you get hours in the 24-hour format).

Ah, well. :)

jaclaz

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy