Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Batch File keeps looping, but why?

Tags:

batch-file

I have written a batch file from a VB.NET program I'm creating.

When I double click on the file in Windows XP it brings up a Command Prompt and appears to be running over and over again.

My batch file is as follows

REG ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename" /ve /t REG_SZ  /d "Open With Rename" /f REG ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename\Command" /ve /t REG_SZ  /d "P:\Misc\Rename v2.0\Rename v2.0\bin\Debug\Rename v2.0.exe ""%1""" /f EXIT 

I can't understan what I've done wrong, but if I open a command prompt and run it from there, it runs once.

Any help would be gratly appreciated!

Thanks

like image 954
Ste Moore Avatar asked Sep 27 '13 09:09

Ste Moore


People also ask

How do I stop a batch file from looping?

The only way to stop an infinitely loop in Windows Batch Script is by either pressing Ctrl + C or by closing the program.

Why do batch files start with @echo off?

If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.

What does %1 mean in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.


Video Answer


1 Answers

In windows, if you have a command line executable with the same name of your bat filename, and the batch file contains this command, the batch file keeps looping.

Example:

  • Create the file net.bat on your desktop.
  • In your file write this text: net

Double click the file and it will keep looping.

The cause of this behaviour is the order of execution of the commands. The command you want to execute is in one of the folders in your path. But the batch file is in your current folder so it gets executed first, causing the loop.

like image 120
Hüseyin Yağlı Avatar answered Sep 22 '22 08:09

Hüseyin Yağlı