Rishav
Rishav

Reputation: 4078

Batch wont execute but just re-print its content

No matter what my code is, even if my batch file is syntactically incorrect, even if it is absolutely correct and even if there is nothing to display on the screen the batch file when executed just displays the code as it is.

I read a similar question MSDOS prints the whole batch file on screen instead of executing but since that was on MS-DOS I hoped my issue could have a solution different than that.

Eg,

@echo off
set abcd=4

Even its batch file would just display the same lines as it is. Please help.

Upvotes: 2

Views: 2892

Answers (4)

DanTes
DanTes

Reputation: 11

Check the file with an editor that allows you to see the encoding. For example Notepad++ , you will see is very different the end of line via CF (\r) and LF (\n)

Your CMD can be recognizing EOL via \n only.

Upvotes: 1

user6466055
user6466055

Reputation:

Try "resetting" cmd if possible. U can try copying someone else's "cmd.exe" and replace it with yours using another bootable OS as windows wont allow that.

Here use my cmd.exe. https://drive.google.com/open?id=0B6ghonMKBfUSLVpRV0U5bG5pQTQ Just in case u need to know I am using Windows 10 64 bit.

Upvotes: 0

Lonkey
Lonkey

Reputation: 193

Perhaps there is a problem with your environment variables. Check the following:

  1. Press WIN + R and run "%SYSTEMROOT%\System32\SystemPropertiesAdvanced.exe"
  2. Click on "Environment Variables"
  3. The system variables are listed at the bottom. Select the variable "Path" and click "Edit..."
  4. Check whether the list contains "C:\Windows\System32" or "%SYSTEMROOT%\System32". If not, add one of those. You may have to restart your computer afterwards.

Upvotes: 0

Filipus
Filipus

Reputation: 540

To determine whether your issue is really with line breaks being converted by your text editor (as the post you mention suggests), perform the following test:

  • Open a Command Line Window
  • Type the following command: copy con test.bat
  • The cursor will reposition itself under the command prompt, this is normal
  • Type the following 3 commands, each followed by the [Enter] key:

.

Echo Off
Set abcd=4
Echo abcd
  • Press CTRL-Z simultaneously (it will show up on screen as ^Z)
  • A confimation message should state: 1 file(s) copied.

Now type Test to run the batch file. If it runs properly, it means you are indeed dealing with line termination issues. Use a different text editor (don't use Notepad!!!), ideally one where you have an option to display the line termination characters (I personnally use NotePad++, it works great for these kinds of things but there are many others out there).

Upvotes: 1

Related Questions