1

...but recognizes 'em just fine when manually entered on the command line.

First time I've seen this in four decades. A new install of win10 Pro 22h2. The batch file in question has run just fine for years on earlier installs. But now? I get this error:

'timeout' is not recognized as an internal or external command, operable program or batch file.

'cmd' is not recognized as an internal or external command, operable program or batch file.

Using 'cmd /c' to call another batch file, so nachurlly the thing just dies. Have checked a couple of other BAT files and those two commands are always kicked out. And, just discovered the that 'taskkill' is not recognized when using 'call' instead of 'cmd /c', though it is, when the called file is run from the command line! (???) Have run SFC with no joy.

5
  • 4
    I'd probably start by seeing what my env settings look like from within the batch, in particular the PATH. Commented Sep 4 at 2:59
  • 1
    Is the batch file run by the same user as CMD? Try making a shortcut to the .bat, and set it to Run as Administrator. Even if you don't want to use that on a regular basis, it could point to the issue. Commented Sep 4 at 3:26
  • Can you try renaming your .bat file to .cmd and see if it works then? the syntax for both files are the same, but .bat uses ancient backwards compatibility which may be why its not working properly. Commented Sep 4 at 8:40
  • The classic cause of this issue is a line starting set path= where the existing Windows %path% is not included in the right side of the equals symbol Commented Sep 4 at 12:51
  • On Stackoverflow, this question would have been closed because it misses a minimum reproducible verifiable example. Create the smallest batch file you can which shows the described behaviour, try it out and then post it as part of your question in full. The current description lets us just shoot in the dark. Commented Sep 5 at 4:57

3 Answers 3

2

So timeout.exe and cmd.exe are not internal commands (from cmd.exe's point of view anyway), but external commands or executables. They both live in c:\windows\system32.

cmd.exe looks in the list of directories in the %PATH% variable for any command that's not an internal command. Typically c:\windows\system32 is in %PATH% but maybe a recent update has changed that.

A set PATH=c:\windows\system32\\;%PATH% will add c:\windows\system32 to the %PATH% variable.

2
  • You can also check if a command is on the path by typing where <command> Commented Sep 4 at 10:15
  • maybe C:\Windows\System32\where.exe if the windows and system32 aren't in the session's path ;-) Commented Sep 4 at 14:15
0

I'd forgotten entirely that you need to put C:\Windows\system32 in the path.

Although why MS doesn't do that on install, I'll never know...

One of the other answers says that that System32 is in the default %PATH% It is not. My Windows 10 install is brand new and and I did not modify the default path in any way, hence the trouble.

1
  • Maybe rather than overusing the word idiot (which I'd say isn't really in keeping with how we do things here), adjusting the answer as if you were writing for someone else to use would be a good idea. We're a Q&A forum, not a site, so metacommentary on an snwer dosen't work great. Commented Sep 11 at 3:27
0

Sounds like your PATHEXT got messed up.

If the .EXE or .CMD/.bat extensions are missing, won’t try them and you’ll get:

>'cmd' is not recognized as an internal or external command, operable program or batch file 

Even though cmd.exe is right there.

It’s obviously not a PATH or cmd.exe problem, it’s the current cmd.exe that was found and is giving its own standard error message when it can’t match the name.

Check with Set pathext to see if PATHEXT is defined and make sure you didn’t create user variables called PATHEXT, PATH, COMSPEC, SYSTEMROOT, WINDIR, etc... that’s not recommended. Good idea to learn the built-in system variables before naming anything.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.