Run other cmd in bat like from it's own path












0















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.










share|improve this question























  • 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


















0















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.










share|improve this question























  • 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
















0












0








0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 27 '14 at 22:12









PiledriverPiledriver

111




111













  • 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



















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












2 Answers
2






active

oldest

votes


















0














There are several options:-




  1. 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.

  2. Create a three-line file callfix.bat containing d:, cd devsys and fix.bat: then call this instead of fix.bat in your parent command.

  3. 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.






share|improve this answer
























  • 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





















0














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 :-)






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    There are several options:-




    1. 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.

    2. Create a three-line file callfix.bat containing d:, cd devsys and fix.bat: then call this instead of fix.bat in your parent command.

    3. 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.






    share|improve this answer
























    • 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


















    0














    There are several options:-




    1. 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.

    2. Create a three-line file callfix.bat containing d:, cd devsys and fix.bat: then call this instead of fix.bat in your parent command.

    3. 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.






    share|improve this answer
























    • 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
















    0












    0








    0







    There are several options:-




    1. 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.

    2. Create a three-line file callfix.bat containing d:, cd devsys and fix.bat: then call this instead of fix.bat in your parent command.

    3. 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.






    share|improve this answer













    There are several options:-




    1. 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.

    2. Create a three-line file callfix.bat containing d:, cd devsys and fix.bat: then call this instead of fix.bat in your parent command.

    3. 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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 27 '14 at 23:04









    AFHAFH

    14.6k31939




    14.6k31939













    • 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





















    • 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



















    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















    0














    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 :-)






    share|improve this answer




























      0














      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 :-)






      share|improve this answer


























        0












        0








        0







        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 :-)






        share|improve this answer













        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 :-)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 27 '14 at 23:05









        dbenhamdbenham

        7,90142030




        7,90142030






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido