Why does the ping command in my batch file execute in a loop and navigates to the beginning?
up vote
0
down vote
favorite
I created a .BAT
file in Windows 10 that has the following lines:
set /p ipadress="Please select your favourite IP-adress."
echo %ipadress%
ping %ipadress% -n 10
However, when I navigate on this batch file to ping, I can see the ping
command repeatedly being executed in a loop. I even tried to rename the ping.BAT
to ping.CMD
but the result is the same.
It works until the second line. After repeating the selected IP address, it ends in a loop and jumps to the beginning of my batch file.
I want to avoid writing ping
command through the command prompt, which is why I created the batch file. I don't know why the ping
command is being continuously called when the same statement is put in a batch file.
Do you have any ideas?
batch-file
|
show 4 more comments
up vote
0
down vote
favorite
I created a .BAT
file in Windows 10 that has the following lines:
set /p ipadress="Please select your favourite IP-adress."
echo %ipadress%
ping %ipadress% -n 10
However, when I navigate on this batch file to ping, I can see the ping
command repeatedly being executed in a loop. I even tried to rename the ping.BAT
to ping.CMD
but the result is the same.
It works until the second line. After repeating the selected IP address, it ends in a loop and jumps to the beginning of my batch file.
I want to avoid writing ping
command through the command prompt, which is why I created the batch file. I don't know why the ping
command is being continuously called when the same statement is put in a batch file.
Do you have any ideas?
batch-file
1
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I created a .BAT
file in Windows 10 that has the following lines:
set /p ipadress="Please select your favourite IP-adress."
echo %ipadress%
ping %ipadress% -n 10
However, when I navigate on this batch file to ping, I can see the ping
command repeatedly being executed in a loop. I even tried to rename the ping.BAT
to ping.CMD
but the result is the same.
It works until the second line. After repeating the selected IP address, it ends in a loop and jumps to the beginning of my batch file.
I want to avoid writing ping
command through the command prompt, which is why I created the batch file. I don't know why the ping
command is being continuously called when the same statement is put in a batch file.
Do you have any ideas?
batch-file
I created a .BAT
file in Windows 10 that has the following lines:
set /p ipadress="Please select your favourite IP-adress."
echo %ipadress%
ping %ipadress% -n 10
However, when I navigate on this batch file to ping, I can see the ping
command repeatedly being executed in a loop. I even tried to rename the ping.BAT
to ping.CMD
but the result is the same.
It works until the second line. After repeating the selected IP address, it ends in a loop and jumps to the beginning of my batch file.
I want to avoid writing ping
command through the command prompt, which is why I created the batch file. I don't know why the ping
command is being continuously called when the same statement is put in a batch file.
Do you have any ideas?
batch-file
batch-file
edited Nov 27 at 9:17
Kamil Maciorowski
23.3k155072
23.3k155072
asked Nov 27 at 8:22
Nils
11
11
1
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59
|
show 4 more comments
1
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59
1
1
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
From comments:
they loop to the german "old" text, which doesn't exist in the batch file anymore
Some old file is named ping.bat
and it's in the same folder. ping %ipadress% -n 10
from your new file calls the old file. The old file probably calls ping
(i.e. itself), hence the loop.
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
(source, emphasis mine).
This also explains why there is absolutely no output from the ping
utility in the screenshot you provided.
Solution: delete or rename the ping.bat
file or explicitly run ping.exe
to avoid running a different extension file with the same name (in current folder/preceeding in path).
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe yourping.exe
is broken or there's a "fake"ping.exe
preceding the right one in your%PATH
.
– Kamil Maciorowski
Nov 27 at 12:43
|
show 4 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1378678%2fwhy-does-the-ping-command-in-my-batch-file-execute-in-a-loop-and-navigates-to-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
From comments:
they loop to the german "old" text, which doesn't exist in the batch file anymore
Some old file is named ping.bat
and it's in the same folder. ping %ipadress% -n 10
from your new file calls the old file. The old file probably calls ping
(i.e. itself), hence the loop.
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
(source, emphasis mine).
This also explains why there is absolutely no output from the ping
utility in the screenshot you provided.
Solution: delete or rename the ping.bat
file or explicitly run ping.exe
to avoid running a different extension file with the same name (in current folder/preceeding in path).
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe yourping.exe
is broken or there's a "fake"ping.exe
preceding the right one in your%PATH
.
– Kamil Maciorowski
Nov 27 at 12:43
|
show 4 more comments
up vote
1
down vote
From comments:
they loop to the german "old" text, which doesn't exist in the batch file anymore
Some old file is named ping.bat
and it's in the same folder. ping %ipadress% -n 10
from your new file calls the old file. The old file probably calls ping
(i.e. itself), hence the loop.
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
(source, emphasis mine).
This also explains why there is absolutely no output from the ping
utility in the screenshot you provided.
Solution: delete or rename the ping.bat
file or explicitly run ping.exe
to avoid running a different extension file with the same name (in current folder/preceeding in path).
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe yourping.exe
is broken or there's a "fake"ping.exe
preceding the right one in your%PATH
.
– Kamil Maciorowski
Nov 27 at 12:43
|
show 4 more comments
up vote
1
down vote
up vote
1
down vote
From comments:
they loop to the german "old" text, which doesn't exist in the batch file anymore
Some old file is named ping.bat
and it's in the same folder. ping %ipadress% -n 10
from your new file calls the old file. The old file probably calls ping
(i.e. itself), hence the loop.
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
(source, emphasis mine).
This also explains why there is absolutely no output from the ping
utility in the screenshot you provided.
Solution: delete or rename the ping.bat
file or explicitly run ping.exe
to avoid running a different extension file with the same name (in current folder/preceeding in path).
From comments:
they loop to the german "old" text, which doesn't exist in the batch file anymore
Some old file is named ping.bat
and it's in the same folder. ping %ipadress% -n 10
from your new file calls the old file. The old file probably calls ping
(i.e. itself), hence the loop.
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
(source, emphasis mine).
This also explains why there is absolutely no output from the ping
utility in the screenshot you provided.
Solution: delete or rename the ping.bat
file or explicitly run ping.exe
to avoid running a different extension file with the same name (in current folder/preceeding in path).
edited Nov 27 at 12:02
community wiki
5 revs, 2 users 96%
Kamil Maciorowski
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe yourping.exe
is broken or there's a "fake"ping.exe
preceding the right one in your%PATH
.
– Kamil Maciorowski
Nov 27 at 12:43
|
show 4 more comments
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe yourping.exe
is broken or there's a "fake"ping.exe
preceding the right one in your%PATH
.
– Kamil Maciorowski
Nov 27 at 12:43
2
2
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
Or explicitly run ping.exe to avoid running a different extension file with the same name. (+1)
– LotPings
Nov 27 at 11:53
1
1
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
@LotPings Good idea. My answer is now community wiki, it includes your useful comment.
– Kamil Maciorowski
Nov 27 at 11:57
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
we checked this again, now we have a "solution". on an another notebook, the batch file is running fine. we think, that we have crashed a system-variable, but we checked this in a tool.now we install windows new. do you have any idea?
– Nils
Nov 27 at 12:34
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
explicitly run ping.exe does not work as well. i mean, we solve the problem. but for the future its cannot be a solution, to install windows again, because of a problem in a batch file.... :-)
– Nils
Nov 27 at 12:40
@Nils So maybe your
ping.exe
is broken or there's a "fake" ping.exe
preceding the right one in your %PATH
.– Kamil Maciorowski
Nov 27 at 12:43
@Nils So maybe your
ping.exe
is broken or there's a "fake" ping.exe
preceding the right one in your %PATH
.– Kamil Maciorowski
Nov 27 at 12:43
|
show 4 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1378678%2fwhy-does-the-ping-command-in-my-batch-file-execute-in-a-loop-and-navigates-to-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome to SuperUser! How is the batch file being called? can you show the output you get?
– Stese
Nov 27 at 8:25
the batch file is called "Ping2".
– Nils
Nov 27 at 8:29
rename it test.bat and try it again.
– Stese
Nov 27 at 8:31
it does the same, it ends in a loop.
– Nils
Nov 27 at 8:56
![output] (imgur.com/a/v9KqX3c)
– Nils
Nov 27 at 8:59