Dos commands are not recognised in batch scri

November 9, 2010 at 03:02:05
Specs: Windows 2003 server
Dos commands like date,time,cd stopped recognizing under batch script which is working fine earlier. There is no change done to script also. I am surprised by this behavior but not sure how to fix.

Code:
------
for /f "tokens=1,2,3 delims=/" %%i in ('date /t') do set CurrDate=%%i_%%j_%%k
set CurrDate=%CurrDate: =_%
for /f "tokens=1,2 delims=:" %%i in ('time /t') do set RET=%%i%%j
set RET=%RET: =%

Error Details:
---------------
for /f "tokens=1,2 delims=:" %%i in ('time /t') do set RET=%%i%%j
set RET=%RET: =%
set RET=%CurrDate%_%RET%

Can some one help !!! pls


See More: Dos commands are not recognised in batch scri

Report •

#1
November 9, 2010 at 03:25:44
Those are the error details?


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 9, 2010 at 22:16:43
Sorry By mistake i pasted the code only for error:

Error Details:
-------------
'date /t' is not recognized as an internal or external command,
operable program or batch file.
'time /t' is not recognized as an internal or external command,
operable program or batch file.
'cd' is not recognized as an internal or external command,
operable program or batch file.


Report •

#3
November 10, 2010 at 05:43:15
Sounds like you need a fresh copy of CMD.EXE


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
November 10, 2010 at 22:39:03
Mechanix2Go,

Actually commands are getting recognized from command prompt. Only as part of Batch script they are not recognized.

If i take a fresh copy of cmd.exe will it solve the issue?



Report •

#5
November 11, 2010 at 04:29:27
One way to find out.


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
November 11, 2010 at 04:59:40
Hi M2!


I've seen cmd do some strange things if unwanted characters(i.e non-printable) get into a script (probably from hitting alt and a num key by accident). It might be worth checking........

I'm not sure about this one but I have seen it refuse to recognise :labels due to some character. I can't remember exactly what it was but I would guess a NUL or ^Z.


Report •

#7
November 11, 2010 at 05:37:52
Hi Judago,

I agree. If it works when typed but not in the script, very likely the script is hosed.


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
November 21, 2010 at 08:01:38
I just happened upon your conversation this morning folks and can vouch for the problem. For my company I was running fine under XP on one laptop and was assigned a new laptop for a promotion I took running 64 bit XP.

As 'sanapart' states, SOME commands in a batch file do not run. I can open a command prompt and change directory in to the same directory that I run the script from, then run that same command without a problem......


Report •

#9
November 21, 2010 at 08:18:25
Let me add a few more clues to this that I seen occur in my current situation. On my old laptop I had been using some unix type commands that were ported over to Windows, ie 'cut', 'grep', 'ssed', etc... Now only a few of those types of commands do not work on the 64 bit OS of the new laptop in a batch file. As I also said before, I can open a command prompt and change directory in to the same directory that I run the script from, then run those same commands without a problem. I seen my problem with the 'cut' command.

Report •

#10
November 21, 2010 at 08:30:07
Sounds like an issue to take up with whoever ported the utilities.

WinXP x64 development started just before Microsoft decided to push the PC market to 64-bit. It might be worth the hassle to install a version of Windows more readily supported.

How To Ask Questions The Smart Way


Report •

#11
November 21, 2010 at 08:41:30
Just found the solution... Or at least the direction to the solution. For those commands that are failing in the batch file, I had to precede those commnds with the 'cmd' command and the switch /C. Evidently the failing commands need to be run specifically by the 64 bit command processor. The command processor that is called by a batch file only uses the 16 bit command processor. In other words to get my batch file to run I had to change the failing commands like this.

original command in the batch file.
cut -f1 -d":" .\MyTimes\%SR%\Start > .\MyTimes\%SR%\StartHours

new command in the batch file.
CMD /C cut -f1 -d":" .\MyTimes\%SR%\Start > .\MyTimes\%SR%\StartHours


Report •

#12
November 21, 2010 at 08:57:25
But now this brings up another pain for me. I have a batch file that has over 2k lines of commands. Now either I add that string to the beginning of each line with a failing command or I add it to all lines.... I see which one may be the easier option.

I wonder if I can add only one line to the beginning of the batch " CMD /K " to stay in the 64 bit engine until the batch finishes.


Report •

#13
November 21, 2010 at 09:08:27
Nope, the best solution is to create a new script that starts the 64 bit processor, then runs the batch file as a command in it. ie...

CMD /C (batchfile.bat)


Report •

#14
November 21, 2010 at 10:27:55
@glcschaefer, I'm glad you've found a solution but I suspect yours is a different issue to sanapart's. You're using 64-bit XP, sanapart is using Windows Server 2003 (presumably 32-bit but hasn't stated.)

@sanapart, see Judago's advice, but if that isn't it, try the following.

It could be the file association for .bat (or .cmd) files. Try typing this (the bold bits) at the command prompt:

C:\> assoc .bat
.bat=batfile
C:\> ftype batfile

Let us know the results. Substitute .cmd for .bat if your batch files are named .cmd.


Report •

#15
November 21, 2010 at 22:09:12
Based on Judago's advice i cross verified the script with stable copy but there is no change nor any unnecessary characters

@Klint
These are results for the commands you asked to execute:

C:\jdevhome\test>assoc .bat
.bat=batfile

C:\jdevhome\test>ftype batfile
batfile="%1" %*

My Windows Server 2003 is 32 bit processor.
I observed DOS commands are not getting recognized in batch script when they are part of for loop as stated in my first query as:
for /f "tokens=1,2,3 delims=/" %%i in ('date /t') do set CurrDate=%%i_%%j_%%k
set CurrDate=%CurrDate: =_%
for /f "tokens=1,2 delims=:" %%i in ('time /t') do set RET=%%i%%j
set RET=%RET: =%

Can someone help


Report •

#16
November 21, 2010 at 22:11:54
I also took fresh copy of CMD.exe but that doesn't helped me to fix the problem

Report •

#17
November 22, 2010 at 01:47:37
Never seen this behaviour before. Does it work when you do this:

for /f "tokens=1,2,3 delims=/" %%i in ('cmd /c date /t') do set CurrDate=%%i_%%j_%%k

i.e. when you insert cmd /c in front of the internal commands date, time and cd?

Also, what is the value of %comspec% ?


Report •

#18
November 22, 2010 at 02:26:09
@klint,

even 'cmd /c date/t' is as well not recognizing any DOS commands.

variable %comspec% is referring to wrong path of CMD.exe . Once after modifying the environment variable %comspec% to correct path of CMD.exe. It is working fine and recognizing all dos commands with in the script.
I just ran the script and worked fine.

I was struggling on this issue from more than 3 weeks.It was resolved now

Thanks for the clue.It helped a lot :)


Report •

Ask Question