Run other cmd in bat like from it's own path
I need to run bat(fix.bat) in cmd batch file (let's say sample.cmd on c:)
The problem is that despite of using:
start /WAIT cmd.exe /C D:devsysfix.bat
fix.bat runs like from parent command (c:sample.cmd) but I need to force it to run from its path ("d:devsys")
How to run bat in other bat so the second one will run like executed from it's own path where it's located?
There in example would help to enter:
"cd d:devsys" and then call for fix.bat but I want to avoid that.
batch batch-file cmd.exe
add a comment |
I need to run bat(fix.bat) in cmd batch file (let's say sample.cmd on c:)
The problem is that despite of using:
start /WAIT cmd.exe /C D:devsysfix.bat
fix.bat runs like from parent command (c:sample.cmd) but I need to force it to run from its path ("d:devsys")
How to run bat in other bat so the second one will run like executed from it's own path where it's located?
There in example would help to enter:
"cd d:devsys" and then call for fix.bat but I want to avoid that.
batch batch-file cmd.exe
Is there any particular reason why you're sayingstart /WAIT cmd /c "command"
instead of saying justcmd /c "command"
?
– G-Man
Aug 27 '14 at 23:13
add a comment |
I need to run bat(fix.bat) in cmd batch file (let's say sample.cmd on c:)
The problem is that despite of using:
start /WAIT cmd.exe /C D:devsysfix.bat
fix.bat runs like from parent command (c:sample.cmd) but I need to force it to run from its path ("d:devsys")
How to run bat in other bat so the second one will run like executed from it's own path where it's located?
There in example would help to enter:
"cd d:devsys" and then call for fix.bat but I want to avoid that.
batch batch-file cmd.exe
I need to run bat(fix.bat) in cmd batch file (let's say sample.cmd on c:)
The problem is that despite of using:
start /WAIT cmd.exe /C D:devsysfix.bat
fix.bat runs like from parent command (c:sample.cmd) but I need to force it to run from its path ("d:devsys")
How to run bat in other bat so the second one will run like executed from it's own path where it's located?
There in example would help to enter:
"cd d:devsys" and then call for fix.bat but I want to avoid that.
batch batch-file cmd.exe
batch batch-file cmd.exe
asked Aug 27 '14 at 22:12
PiledriverPiledriver
111
111
Is there any particular reason why you're sayingstart /WAIT cmd /c "command"
instead of saying justcmd /c "command"
?
– G-Man
Aug 27 '14 at 23:13
add a comment |
Is there any particular reason why you're sayingstart /WAIT cmd /c "command"
instead of saying justcmd /c "command"
?
– G-Man
Aug 27 '14 at 23:13
Is there any particular reason why you're saying
start /WAIT cmd /c "command"
instead of saying just cmd /c "command"
?– G-Man
Aug 27 '14 at 23:13
Is there any particular reason why you're saying
start /WAIT cmd /c "command"
instead of saying just cmd /c "command"
?– G-Man
Aug 27 '14 at 23:13
add a comment |
2 Answers
2
active
oldest
votes
There are several options:-
- Create a link using explorer: locate fix.bat, right click, select Copy, right click elsewhere and select Paste Shortcut; now rename to get rid of "Shortcut to " from the name and maybe the ".bat" as well: then change your parent command to call D:devsysfix.lnk instead of D:devsysfix.bat and the link will set the directory.
- Create a three-line file callfix.bat containing
d:
,cd devsys
andfix.bat
: then call this instead of fix.bat in your parent command. - In your parent command use
start /WAIT cmd.exe /C "D: & cd devsys & fix.bat"
.
Your choice will depend on which you find easiest to maintain and extend if your requirements change.
You can combineD:
andcd devsys
intocd /d D:devsys
. And you might want to use&&
instead of&
, sofix.bat
doesn't run (in the current directory) if thecd
fails (although I guess that's less of an issue iffix.bat
is inD:devsys
).
– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing outcd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about&&
is worth making.
– AFH
Aug 27 '14 at 23:24
add a comment |
You only have 2 choices.
1) Change your current directory within your sample.cmd script:
pushd d:devsys
start /wait cmd.exe /c fix.bat
But you have stated you don't want to do that.
2) The only other choice is to modify fix.bat to change the current directory to where it is executing. The simplest way to do this is to add the following line at (or near) the top of the script:
pushd "%~f0"
But this could change the behavior for other users that expect the script to work from the current directory when the script is called.
EDIT or adopt one of the other suggestions from AFH :-)
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%2f803956%2frun-other-cmd-in-bat-like-from-its-own-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are several options:-
- Create a link using explorer: locate fix.bat, right click, select Copy, right click elsewhere and select Paste Shortcut; now rename to get rid of "Shortcut to " from the name and maybe the ".bat" as well: then change your parent command to call D:devsysfix.lnk instead of D:devsysfix.bat and the link will set the directory.
- Create a three-line file callfix.bat containing
d:
,cd devsys
andfix.bat
: then call this instead of fix.bat in your parent command. - In your parent command use
start /WAIT cmd.exe /C "D: & cd devsys & fix.bat"
.
Your choice will depend on which you find easiest to maintain and extend if your requirements change.
You can combineD:
andcd devsys
intocd /d D:devsys
. And you might want to use&&
instead of&
, sofix.bat
doesn't run (in the current directory) if thecd
fails (although I guess that's less of an issue iffix.bat
is inD:devsys
).
– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing outcd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about&&
is worth making.
– AFH
Aug 27 '14 at 23:24
add a comment |
There are several options:-
- Create a link using explorer: locate fix.bat, right click, select Copy, right click elsewhere and select Paste Shortcut; now rename to get rid of "Shortcut to " from the name and maybe the ".bat" as well: then change your parent command to call D:devsysfix.lnk instead of D:devsysfix.bat and the link will set the directory.
- Create a three-line file callfix.bat containing
d:
,cd devsys
andfix.bat
: then call this instead of fix.bat in your parent command. - In your parent command use
start /WAIT cmd.exe /C "D: & cd devsys & fix.bat"
.
Your choice will depend on which you find easiest to maintain and extend if your requirements change.
You can combineD:
andcd devsys
intocd /d D:devsys
. And you might want to use&&
instead of&
, sofix.bat
doesn't run (in the current directory) if thecd
fails (although I guess that's less of an issue iffix.bat
is inD:devsys
).
– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing outcd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about&&
is worth making.
– AFH
Aug 27 '14 at 23:24
add a comment |
There are several options:-
- Create a link using explorer: locate fix.bat, right click, select Copy, right click elsewhere and select Paste Shortcut; now rename to get rid of "Shortcut to " from the name and maybe the ".bat" as well: then change your parent command to call D:devsysfix.lnk instead of D:devsysfix.bat and the link will set the directory.
- Create a three-line file callfix.bat containing
d:
,cd devsys
andfix.bat
: then call this instead of fix.bat in your parent command. - In your parent command use
start /WAIT cmd.exe /C "D: & cd devsys & fix.bat"
.
Your choice will depend on which you find easiest to maintain and extend if your requirements change.
There are several options:-
- Create a link using explorer: locate fix.bat, right click, select Copy, right click elsewhere and select Paste Shortcut; now rename to get rid of "Shortcut to " from the name and maybe the ".bat" as well: then change your parent command to call D:devsysfix.lnk instead of D:devsysfix.bat and the link will set the directory.
- Create a three-line file callfix.bat containing
d:
,cd devsys
andfix.bat
: then call this instead of fix.bat in your parent command. - In your parent command use
start /WAIT cmd.exe /C "D: & cd devsys & fix.bat"
.
Your choice will depend on which you find easiest to maintain and extend if your requirements change.
answered Aug 27 '14 at 23:04
AFHAFH
14.6k31939
14.6k31939
You can combineD:
andcd devsys
intocd /d D:devsys
. And you might want to use&&
instead of&
, sofix.bat
doesn't run (in the current directory) if thecd
fails (although I guess that's less of an issue iffix.bat
is inD:devsys
).
– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing outcd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about&&
is worth making.
– AFH
Aug 27 '14 at 23:24
add a comment |
You can combineD:
andcd devsys
intocd /d D:devsys
. And you might want to use&&
instead of&
, sofix.bat
doesn't run (in the current directory) if thecd
fails (although I guess that's less of an issue iffix.bat
is inD:devsys
).
– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing outcd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about&&
is worth making.
– AFH
Aug 27 '14 at 23:24
You can combine
D:
and cd devsys
into cd /d D:devsys
. And you might want to use &&
instead of &
, so fix.bat
doesn't run (in the current directory) if the cd
fails (although I guess that's less of an issue if fix.bat
is in D:devsys
).– G-Man
Aug 27 '14 at 23:10
You can combine
D:
and cd devsys
into cd /d D:devsys
. And you might want to use &&
instead of &
, so fix.bat
doesn't run (in the current directory) if the cd
fails (although I guess that's less of an issue if fix.bat
is in D:devsys
).– G-Man
Aug 27 '14 at 23:10
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing out
cd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about &&
is worth making.– AFH
Aug 27 '14 at 23:24
I usually use TCC instead of CMD, so I haven't kept up with all the details of CMD commands, so thanks for pointing out
cd /d
. My second suggestion was proposed to allow flexibility for adding error handling, though your point about &&
is worth making.– AFH
Aug 27 '14 at 23:24
add a comment |
You only have 2 choices.
1) Change your current directory within your sample.cmd script:
pushd d:devsys
start /wait cmd.exe /c fix.bat
But you have stated you don't want to do that.
2) The only other choice is to modify fix.bat to change the current directory to where it is executing. The simplest way to do this is to add the following line at (or near) the top of the script:
pushd "%~f0"
But this could change the behavior for other users that expect the script to work from the current directory when the script is called.
EDIT or adopt one of the other suggestions from AFH :-)
add a comment |
You only have 2 choices.
1) Change your current directory within your sample.cmd script:
pushd d:devsys
start /wait cmd.exe /c fix.bat
But you have stated you don't want to do that.
2) The only other choice is to modify fix.bat to change the current directory to where it is executing. The simplest way to do this is to add the following line at (or near) the top of the script:
pushd "%~f0"
But this could change the behavior for other users that expect the script to work from the current directory when the script is called.
EDIT or adopt one of the other suggestions from AFH :-)
add a comment |
You only have 2 choices.
1) Change your current directory within your sample.cmd script:
pushd d:devsys
start /wait cmd.exe /c fix.bat
But you have stated you don't want to do that.
2) The only other choice is to modify fix.bat to change the current directory to where it is executing. The simplest way to do this is to add the following line at (or near) the top of the script:
pushd "%~f0"
But this could change the behavior for other users that expect the script to work from the current directory when the script is called.
EDIT or adopt one of the other suggestions from AFH :-)
You only have 2 choices.
1) Change your current directory within your sample.cmd script:
pushd d:devsys
start /wait cmd.exe /c fix.bat
But you have stated you don't want to do that.
2) The only other choice is to modify fix.bat to change the current directory to where it is executing. The simplest way to do this is to add the following line at (or near) the top of the script:
pushd "%~f0"
But this could change the behavior for other users that expect the script to work from the current directory when the script is called.
EDIT or adopt one of the other suggestions from AFH :-)
answered Aug 27 '14 at 23:05
dbenhamdbenham
7,90142030
7,90142030
add a comment |
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%2f803956%2frun-other-cmd-in-bat-like-from-its-own-path%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
Is there any particular reason why you're saying
start /WAIT cmd /c "command"
instead of saying justcmd /c "command"
?– G-Man
Aug 27 '14 at 23:13