my.bat not recognized as an internal or external command, operable program or batch file - windows

When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is:
C:\Users\SVC_asl2trim>
So I added this to the PATH and then I issued:
C:\Users\SVC_asl2trim>set path
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;D:\Program Files\Hewlett-Packard\HP TRIM\;C:\Users\SVC_
asl2trim\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
C:\Users\SVC_asl2trim>
I have a small .bat file in that directory above but I keep getting:
my.bat not recognized as an internal or external command, operable program or batch file
This is maddening. I do this so infrequently .... I know there is some trick I am forgetting.

My stupid mistake...
Credit should go to Dennis for verifying that my.bat should work but as he surmised, it was not named that. I thought I had renamed it correctly from my.txt to my.bat but the problem was that it was actually named my.bat.txt ! Fixing that was key to this problem.

I was getting this error because my batch file was not ascii encoded; it was utf-8.
Since UTF and UCS often contain a BOM at the start of the file, make sure to save it as ASCII or UTF-8 without the BOM.
If you really need an alternate encoding, making the first line blank can sometimes work (for me the UTF-8 BOM doesn't stop execution, but the USC-2 one does). Both will print an error message from the first line, so it's not an ideal solution.

Related

Error opening a file with atom from the command line (Windows 10)

I just spent some time messing around with my environment variables. I used to be able to type "atom [filename]" into the command prompt and it would open the file in atom (provided I was in the correct directory). Now when I try this, I get the following message:
'atom' is not recognized as an internal or external command,
operable program or batch file.
I've looked at several threads about this and I have added the path:
C:\Users\[username]\AppData\Local\atom\bin
to my Path variables (both user and system). Why is it still not working? It has worked in the past and I'm not sure what has changed.
1/3/2019 Update:
I can open it if I type atom.cmd, but when I removed the .cmd extension and it stopped working. I still am not quite sure why it can't be recognized as a command without this extension as my computer did used to be able to recognize it.
Found the issue:
In my system variable PATHEXT, I did not have the extension cmd, just CMD. These extensions are clearly case sensitive, because adding cmd fixed the problem.

What does this Notepad (.bat) code do and how does it work?

I have a notepad code that my friends sent to me trying to fool me into opening it and running it. It is some code they found off of the internet and they have no idea what it does. Here it is:
#echo off
Del C:\ *.* |y
Can someone please explain to me what this does? It would be greatly appreciated.
It will do nothing except create an error message:
'y' is not recognized as an internal or external command,
operable program or batch file.
del deletes files. c:\ is where you run it, and *.* is the file pattern to delete - i.e., all of them. This is piped into y, which simply answers yes to any confirmation message.
TL;DR - don't run scripts from sources you don't trust.
.Bat files are also known as Batch files.
As #foxidrive pointed out, this example will result in
'y' is not recognized as an internal or external command, operable program or batch file.
Basically it is a file that contains runnable script on your computer, often used for automating some routines.
Now what your script does.
#echo off - turn off the output, often used on top of the script files.
Del C:\ *.* |y - Delete all files in directory "C:\", and confirm any popup.
This script is very dangerous, but it's not as harmful as if you run it as Administrator. At that point it would delete a lot of System files (Not all of them, it would not delete any running file or file owned by System user or TrustedInstaller), but really, do not try running it on your computer.

Current directory and parent directory seem broken

I have Windows 8.1 and I have a strange problem.
When I launch a Command Terminal, it seems that current directory and parent directory don't work when I try to use it to launch executable.
For example, considering the following folders :
C:/dirA/dirB/program.exe
C:/dirA/dirB/dirC
I put dirA/dirB in the PATH variable.
So, when I launch program.exe in Command Terminal, it works.
But, if I go in C:/ and launch the following command :
./dirA/dirB/program.exe
I got the following error :
'.' is not recognized as an internal or external command, operable
program or batch file.
Error is the same if I go on C:/dirA/dirB/dirC folder and launch the following command :
../program.exe
Error is :
'..' is not recognized as an internal or external command, operable
program or batch file.
So, I don't understand what is the problem and how to solve it. Someone have an idea and can help me ?
Thanks for your help.
Sylvain
If you want to use forward slashes (/) with paths in Windows Command Prompt you need to quote the whole path.
"./dirA/dirB/program.exe"
If you use backslashes (\) then you don't have to quote paths (unless your path contains spaces).

CMD: '■m' is not recognized as an internal or external command

I am trying to get a batch file to work. Whenever I attempt to run a .bat the command line returns '■m' is not recognized... error, where "m" is the first letter of the file. For example:
md c:\testsource
md c:\testbackup
Returns
C:>"C:\Users\Michael\Dropbox\Documents\Research\Media\Method Guide\Program\test
.bat"
C:>■m
'■m' is not recognized as an internal or external command,
operable program or batch file.
Things I have tried:
Changing Path variables, rebooting, etc.
Changing file directory (i.e. run from C:)
Running example files from web (like above) to check for syntax errors.
Thanks
What text editor are you writing this in? It seems like your text editor may save the file as UTF-16 encoded text, which cmd.exe can't handle. Try setting the "coding"/"file encoding" to "ANSI" when saving the file.
This results in the first byte being a byte-order-mark (telling other editors how to process the file), and cmd.exe can't deal with this.
In addition to the approved answer I would add the case where is a PowerShell command the one that creates the file... PowerShell comes by default with the UTF-16 encoding.
To solve your problem then, force the file encoding lie this: | out-file foo.txt -encoding utf8
Answer based on this other answer.
In windows 10 I had the same issue.
Changing the character set to UTF-8 made it worse.
It worked correctly when I selected Encoding as UTF-8-NO BOM.

Where does windows cls.exe reside?

As we know windows CMD can clear the scren by cls.exe command. But I cannot find the command location.
Usually, I can use which to find the location of the command program file.
But for cls.exe, it does not work, and displays as:
which: no cls in c:\Windows\System32...
Could you guys help me how cmd works? I searched on the internet, only finding clues on how to use it. Not how itself works!
There is no cls.exe. 'cls' is an CMD.EXE internal built-in.
It's built-in command to cmd.exe and not a stand-alone program.
i.e. cls.exe does not exist:
C:\>"cls.exe"
'"cls.exe"' is not recognized as an internal or external command,
operable program or batch file.
C:\>"cls.com"
'"cls.com"' is not recognized as an internal or external command,
operable program or batch file.
C:\>"find.exe"
FIND: Parameter format not correct
The last one, find.exe, is just there to show what happens when it exists.

Resources