|
Answer» Hello everybody. I'm having problems with a file batch, in fact, I have two files, they are the following:
reloj.bat: @echo off date time pause
reloj.txt:
(It is just an "enter.")
Then I run reloj.bat from CMD and it jumps directly to the pause command and displays the message "Press any key to continue . . . " To make clear some points: I've tried this batch program in windows 7 32 bits, windows 7 64 bits and windows xp 32 bits, but in all those operating systems it has just failed, and something else, they all were virtual machines. Does anyone have any idea of how to succeed this problem? I really need it for this class guys.
Thanks for your help, see you!
Untested, but maybe it has to be % % for these.
reloj.bat: @echo off %date% %time% pause
reloj.txt:No, Dave, that won't do anything. Memowii -
1. What are you INTENDING to achieve?
2. What are the outputs of the date and time commands on your system?
To clarify, on my system the date command gives an output like this
c:\>date The current date is: 03/09/2015 Enter the new date: (dd-mm-yy)
and the time command gives an output like this
c:\>time The current time is: 18:02:29.90 Enter the new time:
What I am getting at is this:
What this line of code: date <reloj.txt | find "actual" does is this:
Make the date command read its input from reloj.txt (which just contains a newline). This makes it behave the same as if you had run the date command and PRESSED Enter on the keyboard. The date command expects either:
A valid date in your local date format as shown in the prompt, i.e. the second line e.g. Enter the new date: (dd-mm-yy) (it changes the system date to whatever you entered)
Or
Enter (it changes nothing and exits.)
Next, both lines of the date command are passed to the find utility, with the search string "actual". The find utility will block any lines that do not contain "actual". If your date command output does not have the word "actual" in either line then nothing will be shown. Likewise for the time command.
I expect you want to show the first lines of the date and time commands. Those are the interesting ones. If you are in an English language locale you would probably do something like this
date <reloj.txt | find "current" time <reloj.txt | find "current"
If you are not actually using the date and time commands in your real script (e.g. you are disguising what is happening in your script) and/or you have locale and language settings other than English, then you have been wasting quite a lot of our time.
By the way, you don't need to use a file with a newline in it to force an Enter into a command; you can use echo. with a pipe like so:
echo. | date
Are you by any chance using Spanish locale where actual means current e.g. hora actual? First of all, I have to say Thank you for your great help and time.
Second, the output that I expected was the following: The current date is: 03/09/2015 The current day is: 20:24:31.37 Press any key to continue...
Third, WELL, the real problem was with the O.S.'s language, as Salmon Trout explained it in his interesting answer. My professor wrote this code in a windows 7 O.S. whose language is Spanish. And I use a virtual machine with windows 7 (32 bits) whose language is English, in fact, all my virtual machines are in English, you know, to practice the language. So, when I saw the word "actual" in my professor's code, I actually thought about the English word "actual": existing in act, fact, or reality; real. And when "actual" is translated into English it becomes "current", and it solves the problem, showing me the output that I've posted in this post.Code: [Select]echo. | DATE | find "current" OR
Code: [Select]<nul set /P .=The Current Date is: &DATE /TWhat's wrong with:
Echo The current date is: %date%
Quote from: Salmon Trout on September 04, 2015, 10:17:07 AM What's wrong with:
Echo The current date is: %date%
That would be way to simple!
|