What's a correct way for a batch file to run itself with params?
I have a batch file. In which, I need to start another copy of itself in a new window with a parameter. I tried the command start "" "%~0" "Param"
but it said '"Param"' is not recognized as an internal or external command, operable program or batch file.
and didn't start anything. The only way I could get it to work was start %~0 Param
, but I figured that would crash if the path had spaces. So What is the correct way to start another instance of the current batch file with parameters?
windows command-line batch parameters
add a comment |
I have a batch file. In which, I need to start another copy of itself in a new window with a parameter. I tried the command start "" "%~0" "Param"
but it said '"Param"' is not recognized as an internal or external command, operable program or batch file.
and didn't start anything. The only way I could get it to work was start %~0 Param
, but I figured that would crash if the path had spaces. So What is the correct way to start another instance of the current batch file with parameters?
windows command-line batch parameters
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05
add a comment |
I have a batch file. In which, I need to start another copy of itself in a new window with a parameter. I tried the command start "" "%~0" "Param"
but it said '"Param"' is not recognized as an internal or external command, operable program or batch file.
and didn't start anything. The only way I could get it to work was start %~0 Param
, but I figured that would crash if the path had spaces. So What is the correct way to start another instance of the current batch file with parameters?
windows command-line batch parameters
I have a batch file. In which, I need to start another copy of itself in a new window with a parameter. I tried the command start "" "%~0" "Param"
but it said '"Param"' is not recognized as an internal or external command, operable program or batch file.
and didn't start anything. The only way I could get it to work was start %~0 Param
, but I figured that would crash if the path had spaces. So What is the correct way to start another instance of the current batch file with parameters?
windows command-line batch parameters
windows command-line batch parameters
edited Jan 25 at 16:21
Mark Deven
asked Jan 25 at 14:42
Mark DevenMark Deven
589322
589322
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05
add a comment |
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05
add a comment |
3 Answers
3
active
oldest
votes
I would start a second cmd shell, something like:
start "" Cmd.exe %~0 parameters
just to give each iteration of the batch file its own command shell.
Note by OP: I had to do the following:
start cmd.exe /C %~0 parameters
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do startcmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
add a comment |
In order to call another batch file from a batch file, use call "name of script.bat"
or `start "name of script.bat"
Although you can do it without, unexpected results will happen, given that it will continuously call itself.
so technically, you can just write
%0 MyParam
add a comment |
To avoid an infinite loop, check if args are present:
:: Q:Test2019125SU_1298393.cmd
@Echo off
If "%~1" neq "" goto :HasArgs
Echo restart with parms
"%~0" "parms"
:HasArgs
Echo %0 started with %*
Pause
Exit /B
Sample run:
> SU_1298393.cmd
restart with parms
"SU_1298393.cmd" started with "parms"
Press any key to continue . . .
> SU_1298393.cmd foo bar
SU_1298393.cmd started with foo bar
Press any key to continue . . .
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
add a comment |
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',
autoActivateHeartbeat: false,
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%2f1398393%2fwhats-a-correct-way-for-a-batch-file-to-run-itself-with-params%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would start a second cmd shell, something like:
start "" Cmd.exe %~0 parameters
just to give each iteration of the batch file its own command shell.
Note by OP: I had to do the following:
start cmd.exe /C %~0 parameters
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do startcmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
add a comment |
I would start a second cmd shell, something like:
start "" Cmd.exe %~0 parameters
just to give each iteration of the batch file its own command shell.
Note by OP: I had to do the following:
start cmd.exe /C %~0 parameters
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do startcmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
add a comment |
I would start a second cmd shell, something like:
start "" Cmd.exe %~0 parameters
just to give each iteration of the batch file its own command shell.
Note by OP: I had to do the following:
start cmd.exe /C %~0 parameters
I would start a second cmd shell, something like:
start "" Cmd.exe %~0 parameters
just to give each iteration of the batch file its own command shell.
Note by OP: I had to do the following:
start cmd.exe /C %~0 parameters
edited Feb 15 at 20:15
Run5k
11.4k73253
11.4k73253
answered Jan 25 at 15:38
LarrycLarryc
67139
67139
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do startcmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
add a comment |
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do startcmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Exactly what I was looking for, don’t know why I didn’t think of that. Thank you!!
– Mark Deven
Jan 25 at 16:11
Actually, this isn't working for me. I had to do start
cmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
Actually, this isn't working for me. I had to do start
cmd.exe /C %~0 parameters
– Mark Deven
Feb 15 at 19:13
add a comment |
In order to call another batch file from a batch file, use call "name of script.bat"
or `start "name of script.bat"
Although you can do it without, unexpected results will happen, given that it will continuously call itself.
so technically, you can just write
%0 MyParam
add a comment |
In order to call another batch file from a batch file, use call "name of script.bat"
or `start "name of script.bat"
Although you can do it without, unexpected results will happen, given that it will continuously call itself.
so technically, you can just write
%0 MyParam
add a comment |
In order to call another batch file from a batch file, use call "name of script.bat"
or `start "name of script.bat"
Although you can do it without, unexpected results will happen, given that it will continuously call itself.
so technically, you can just write
%0 MyParam
In order to call another batch file from a batch file, use call "name of script.bat"
or `start "name of script.bat"
Although you can do it without, unexpected results will happen, given that it will continuously call itself.
so technically, you can just write
%0 MyParam
answered Jan 25 at 15:32
LPChipLPChip
36.3k55487
36.3k55487
add a comment |
add a comment |
To avoid an infinite loop, check if args are present:
:: Q:Test2019125SU_1298393.cmd
@Echo off
If "%~1" neq "" goto :HasArgs
Echo restart with parms
"%~0" "parms"
:HasArgs
Echo %0 started with %*
Pause
Exit /B
Sample run:
> SU_1298393.cmd
restart with parms
"SU_1298393.cmd" started with "parms"
Press any key to continue . . .
> SU_1298393.cmd foo bar
SU_1298393.cmd started with foo bar
Press any key to continue . . .
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
add a comment |
To avoid an infinite loop, check if args are present:
:: Q:Test2019125SU_1298393.cmd
@Echo off
If "%~1" neq "" goto :HasArgs
Echo restart with parms
"%~0" "parms"
:HasArgs
Echo %0 started with %*
Pause
Exit /B
Sample run:
> SU_1298393.cmd
restart with parms
"SU_1298393.cmd" started with "parms"
Press any key to continue . . .
> SU_1298393.cmd foo bar
SU_1298393.cmd started with foo bar
Press any key to continue . . .
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
add a comment |
To avoid an infinite loop, check if args are present:
:: Q:Test2019125SU_1298393.cmd
@Echo off
If "%~1" neq "" goto :HasArgs
Echo restart with parms
"%~0" "parms"
:HasArgs
Echo %0 started with %*
Pause
Exit /B
Sample run:
> SU_1298393.cmd
restart with parms
"SU_1298393.cmd" started with "parms"
Press any key to continue . . .
> SU_1298393.cmd foo bar
SU_1298393.cmd started with foo bar
Press any key to continue . . .
To avoid an infinite loop, check if args are present:
:: Q:Test2019125SU_1298393.cmd
@Echo off
If "%~1" neq "" goto :HasArgs
Echo restart with parms
"%~0" "parms"
:HasArgs
Echo %0 started with %*
Pause
Exit /B
Sample run:
> SU_1298393.cmd
restart with parms
"SU_1298393.cmd" started with "parms"
Press any key to continue . . .
> SU_1298393.cmd foo bar
SU_1298393.cmd started with foo bar
Press any key to continue . . .
answered Jan 25 at 16:02
LotPingsLotPings
5,1151823
5,1151823
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
add a comment |
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
It’s only in a specific case but thank you!
– Mark Deven
Jan 25 at 16:11
add a comment |
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.
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%2f1398393%2fwhats-a-correct-way-for-a-batch-file-to-run-itself-with-params%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
Do you mean another additional instance, and the current stay running?
– LotPings
Jan 25 at 16:05