# Calling all MS-DOS Batch file experts

**URL:** <https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700>\
**Category:** Factual Questions\
**Created:** [March 3, 2003, 3:02am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700 "2003-03-03T03:02:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [March 3, 2003, 3:02am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/1 "2003-03-03T03:02:04Z")

</div>

I realize this question may never get answered here, but it is worth a try…  
How do I obtain information from the user in a batch file (not from the command line paramaters, but after a batch file has been run)

I would have the string “Please enter the date (DDMMYY)” and would then want a variable containing whatever was entered for use later on in the batch file.  
**or** (This will solve the problem also, but is probably more complicated) how would I obtain the date one day prior to the system date into a variable?

Thanks

---

<div class="post-metadata">

**Author:** ![Melraidin](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Melraidin](https://boards.straightdope.com/u/Melraidin)\
**Post date:** [March 3, 2003, 3:15am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/2 "2003-03-03T03:15:04Z")

</div>

Hrmm… it has been quite awhile. What you’re looking for is a program that returns the error code of the key entered…

There were many that would do this, but none can return more than one keystroke. Possibly if you made a simple program in QuickBasic or the like to read in a string or do the calculation and then have that program call a second batch file, passing that information on the command line?

Either way, I believe your best bet is to simply use a compiler like QuickBasic or any C or C++ compiler to create whatever util it is your looking for.

BTW, what is it you’re making?

---

<div class="post-metadata">

**Author:** ![daniel801](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@daniel801](https://boards.straightdope.com/u/daniel801)\
**Post date:** [March 3, 2003, 3:17am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/3 "2003-03-03T03:17:45Z")

</div>

[http://www.robvanderwoude.com/datetiment.html](http://www.robvanderwoude.com/datetiment.html)

Go to Yesterday.bat and this guy has done it for you.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [March 3, 2003, 4:30am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/4 "2003-03-03T04:30:17Z")

</div>

It is for work, so I probably can’t say much.

we have a batch file which gets some files onto a disk from a directory.

some recent changes where we work have meant we need to get some more files. their filenames are the date in YY/MM/DD format and a few characters. the characters are always the same so in theory I could search for “chars\*.ext” which would find all files with ‘chars’ at the beginning. Problem is - this would find more files than I want (the system stores a couple of extra days for backup/safety so I would need to get yestarday’s date to get only yestarday’s file)

Anyway, since posting I have realized that I can do it using our bespoke internal system’s macros. which have some useful commands (such as “set\_local date appl\_date(’-1day’))”) so I am doing it using the macros.

Thanks for the help guys, anyway.

---

<div class="post-metadata">

**Author:** ![Melraidin](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Melraidin](https://boards.straightdope.com/u/Melraidin)\
**Post date:** [March 3, 2003, 4:41am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/5 "2003-03-03T04:41:33Z")

</div>

Just to defend my answer as not being completely out of whack:

Here’s the _NT_ batch file the link daniel801 posted had for getting the date into an env var:

@ECHO OFF  
FOR /F "TOKENS=1\* DELIMS= " %%A IN (‘DATE/T’) DO SET DATE=%%B  
ECHO It’s %DATE% today

Now this seems to work in NT (Actually, I’m just assuming, haven’t tested since don’t have NT). But this would not work in MS-DOS, which is what the OP asked for.

Nitpicking, I know, but I’m bored 'n need something to bolster my waning ego.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [March 3, 2003, 5:48am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/6 "2003-03-03T05:48:35Z")

</div>

**Melraidin** You are probably right. One website I found said something along the same lines as your post. In the end I did sort of take up your suggestion. The language I wrote the macro (It is now done) is similar to basic and C (and sql, and dos, and just about every other simple language!)

---

<div class="post-metadata">

**Author:** ![Bill\_H](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@Bill\_H](https://boards.straightdope.com/u/Bill_H)\
**Post date:** [March 3, 2003, 9:00am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/7 "2003-03-03T09:00:37Z")

</div>

If you do a lot of DOS scripting, check out 4DOS at [jpsoft.com](http://jpsoft.com). It’s a [command.com](http://command.com) replacement, and very cool. It enables the sort of thing you want to do here and much more.

---

<div class="post-metadata">

**Author:** ![essohbee](https://avatars.discourse-cdn.com/v4/letter/e/71c47a/32.png) [@essohbee](https://boards.straightdope.com/u/essohbee)\
**Post date:** [March 3, 2003, 10:54am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/8 "2003-03-03T10:54:57Z")

</div>

On some windows platforms (NT and XP confirmed) you can run [perl](http://www.activestate.com) straight from the commandline like this:

c:\script.pl

Perl contains very powerful string manipulation tools and basic perl is rather easy to learn. I’ve been programming perl for less than 6 months and I could easily write a program as described in the OP

---

<div class="post-metadata">

**Author:** ![essohbee](https://avatars.discourse-cdn.com/v4/letter/e/71c47a/32.png) [@essohbee](https://boards.straightdope.com/u/essohbee)\
**Post date:** [March 3, 2003, 10:59am UTC](https://boards.straightdope.com/t/calling-all-ms-dos-batch-file-experts/158700/9 "2003-03-03T10:59:59Z")

</div>

On some windows platforms (NT and XP confirmed) you can run [perl](http://www.activestate.com) straight from the commandline like this:

c:\script.pl

Perl contains very powerful string manipulation tools and basic perl is rather easy to learn. I’ve been programming perl for less than 6 months and I could easily write a program as described in the OP
