none
CMD Window is not closing automatically after the command executes in a batch file RRS feed

  • Question

  • Hello All,

    I have created a batch file which calls batch of an application. The application runs; however, the DOS window does not exit.  See below what i have in the batch file. I am using windows 7. Any help would be appreciated. 

    @echo off

    set LANG=C

    set 
    PATH="o:\Creo2\Creo2_x32\Parametric\";"o:\Creo2\Creo2_x32\Parametric\bin;%PATH%"

    c:

    if not exist c:\tmp mkdir c:\tmp

    if not exist c:\users\%username%\creo2_pdmlink9_1 mkdir c:\users\%username%\creo2_pdmlink9_1

    set PTC_WF_ROOT=c:\users\%username%\creo2_pdmlink9_1

    cd c:\users\%USERNAME%\creo2_pdmlink9_1

    cls

    call "o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat"

    exit;

    exit;

    • Edited by Nihar Pal Thursday, January 23, 2014 1:47 PM
    • Moved by CoolDadTx Thursday, January 23, 2014 4:46 PM Scripting related
    Thursday, January 23, 2014 1:43 PM

Answers

  • Found a solution here:

    http://www.thefreewindows.com/82/close-a-batch-dos-window-automatically-after-execution/

    start "" "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe" worked for me.

    Friday, January 24, 2014 9:18 PM

All replies

  • Command script questions should be posted in TechNet.  These forums are for development related topics.

    Thursday, January 23, 2014 4:45 PM
  • You have not told us what is in this file:
     call "o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat"


    ¯\_(ツ)_/¯

    Thursday, January 23, 2014 5:30 PM
  • My understanding of CALL is it will wait if the called batch file or executable is doing "stuff" (like waiting for a user's input).

    As jrv has asked, what is in the parametric.bat batch file? Is this batch file completing?


    • Proposed as answer by edeeefde Tuesday, July 4, 2017 7:48 AM
    Thursday, January 23, 2014 6:07 PM
  • The parametric.bat file contains the path to the *.exe file of the application as well as *.psf file (startup file) which contains the license server information, license name etc.
    Thursday, January 23, 2014 7:28 PM
  • When the executable run from parametric.bat ends, does the command window close?


    Thursday, January 23, 2014 7:32 PM
  • The parametric.bat file contains the path to the *.exe file of the application as well as *.psf file (startup file) which contains the license server information, license name etc.

    We need yu to post the contents of the batch file.

    Note tha this forum is for technicians.  It is not an end user support forum.  If you are not a tech and do not understand batch files and/or why we are asking then you may want to contact a consultant to help you.

    Without good and complete information it is not possible to answer your question.  There is not reason toe assume that a "call" statement returns immediately.  It just isn't true.


    ¯\_(ツ)_/¯

    Thursday, January 23, 2014 7:33 PM
  • I have the same problem with the DOS window not closing when executing parametric.bat in a script.  Creo Parametric 2.0 is the latest version of CAD software from PTC.  I did not have the issue of the DOS window hanging up with previous versions of the software (Pro/Engineer WF5).  The DOS window does close when Creo Parametric 2.0 is closed.  Or I can manually close the DOS window with Creo Parametric still running.  I would just prefer the DOS window to close after parametric.bat is executed.
    Friday, January 24, 2014 6:47 PM
  • I have the same problem with the DOS window not closing when executing parametric.bat in a script.
    You need to post the batch file you use, same as the original poster in this thread. Note also that DOS disappeared with Windows ME, some 14 years ago. The black window you're thinking of is the Console. There is no DOS in any of the current versions of Windows.
    Friday, January 24, 2014 7:03 PM
  • Nihar, when calling a program within a cmd.exe window, the cmd.exe window will remain open as long as sub program is running. If you wish the cmd.exe window to close, then open a separate window detached using the "start" command, without the /wait parameter.

    This is batch scripting 101.

    ---

    @echo off

    start notepad.exe


    Keith Garner - keithga.wordpress.com

    Friday, January 24, 2014 7:11 PM
  • Nihar, when calling a program within a cmd.exe window, the cmd.exe window will remain open as long as sub program is running.

    Keith Garner - keithga.wordpress.com

    Not necessarily. It depends on how the application is written. Try this one for a test:

    @echo off
    explorer.exe

    Friday, January 24, 2014 7:27 PM
  • Change this line:

    call "o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat"

    To:

    start cmd /c o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat

    If that doesn't work then you need to contact the vendor.


    ¯\_(ツ)_/¯

    Friday, January 24, 2014 7:40 PM
  • Here is the batch file I am running:

    @echo off
    copy \\maap01\stdpc\Mconfig\WC10_Creo\config.sup "C:\ptc\Creo 2.0\Common Files\M070\text\config.sup"
    rem place "rem" on line below
    copy \\maap01\stdpc\Mconfig\WC10_Creo\config.pro "C:\ptc\Creo 2.0\Common Files\M070\text\config.pro"
    rem place "rem" on line below
    copy \\maap01\stdpc\Mconfig\WC10_Creo\creo_parametric_admin_customization.ui "C:\ptc\Creo 2.0\Common Files\M070\text\creo_parametric_admin_customization.ui"
    copy \\maap01\stdpc\Mconfig\appearance.dmt "C:\ptc\Creo 2.0\Common Files\M070\graphic-library\appearances\appearance.dmt"
    copy \\maap01\stdpc\Mconfig\feature.dat "C:\ptc\Creo 2.0\Common Files\M070\mech\text\licensing\mech\feature.dat"
    copy \\maap01\stdpc\Mconfig\config C:\ptc\config
    "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe"
    @echo off
    Exit

    Friday, January 24, 2014 7:41 PM
    • Use the Start command when invoking your .exe file, as suggested by other respondents.
    • Get rid of the last two lines. They are superfluous.
    • Change your "copy" commands to "copy /y" so that the batch file does not pause in case the target file already exists.
    Friday, January 24, 2014 7:49 PM
  • i'd try the 'start' suggestion of jrv ,

    might want to change the called batch file so that the line reads

    start "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe"

    since you don't the cmd window to stay open , you don't need to wait.

    BTW: does the cmd window close when you finish running parametric.exe ?


    TechNet

    Friday, January 24, 2014 7:51 PM
  • Tried the suggestions above.  When I use "start" the program does not execute.  One other thing, I am using a shortcut to the batch file and setting the Start in folder to c:\ptc\startup with the Run set as Normal window.  Not sure if that has an effect or not.  I can set the Run to Minimized and at least it is not displayed on the screen.
    Friday, January 24, 2014 8:09 PM
  • And the cmd window only closes after I close the parametric.exe program.  The window stays open as long as paremetric.exe is running.  Or if I manually close the cmd window.
    Friday, January 24, 2014 8:10 PM
  • Tried the suggestions above.  When I use "start" the program does not execute.  One other thing, I am using a shortcut to the batch file and setting the Start in folder to c:\ptc\startup with the Run set as Normal window.  Not sure if that has an effect or not.  I can set the Run to Minimized and at least it is not displayed on the screen.

    THe start command MUST be the following:

    start cmd /c o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat

    You have to put on your thinking cap and try to understand what is happening and why.

    Test it by copying and pasting that at a prompt.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, January 24, 2014 8:20 PM
    Friday, January 24, 2014 8:19 PM
  • You may have me confused with Nihar Pal.  My installation is in the C Drive and is "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe".

    Nbula92

    Friday, January 24, 2014 8:27 PM
  • You may have me confused with Nihar Pal.  My installation is in the C Drive and is "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe".

    Nbula92


    You hijacked an existing thread. This is why you should always start your own.

    Don't retire TechNet! - (Don't give up yet - 12,575+ strong and growing)

    Friday, January 24, 2014 8:32 PM
  • You may have me confused with Nihar Pal.  My installation is in the C Drive and is "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe".

    Nbula92

    Please leave the thread as this is not your question.  I am not responding to your questions.

     The OP posted this:

    call "o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat"

    It needs to be this:

    START  CMD /C o:\Creo2\Creo2_x32\Parametric\bin\parametric.bat

    This will launch without wait allowing the calling window to be closed.  If there is another window open then it is the vendors window and the OP needs to contact the vendor to learn why thisis being done.  THer eis a reason for it but I will let the vendor explain.

    The existence of a command window is of no importance.  The called batch has clean up to do after the program terminates so its WIndow cannot be closed. New version new behaviors.  Call vendor.


    ¯\_(ツ)_/¯

    Friday, January 24, 2014 8:36 PM
  • Noted. Please respond to the new thread if you have any ideas  http://social.technet.microsoft.com/Forums/scriptcenter/en-US/d65bc3bb-0ce5-4201-8c59-9682eb5d8393/cmd-window-is-not-closing-automatically-after-the-command-executes-in-a-batch-file-take-2?forum=ITCG

    Thanks.

    Friday, January 24, 2014 8:46 PM
  • Noted. Please respond to the new thread if you have any ideas  http://social.technet.microsoft.com/Forums/scriptcenter/en-US/d65bc3bb-0ce5-4201-8c59-9682eb5d8393/cmd-window-is-not-closing-automatically-after-the-command-executes-in-a-batch-file-take-2?forum=ITCG

    Thanks.

    The vendor site for Creo has information on how to configure Creo correctly.  The Window stays open because the configuration is incorrect or incomplete.  Contact the vendor.

    Note that if you search for this on the Web you will find references to this from 2012 when 2.0 was first released.  We cannot answer this question as it is product related.

    I tried to get you to use START to try and show you that it has nothing to do with your batch file.


    ¯\_(ツ)_/¯

    Friday, January 24, 2014 9:02 PM
  • Found a solution here:

    http://www.thefreewindows.com/82/close-a-batch-dos-window-automatically-after-execution/

    start "" "C:\ptc\Creo 2.0\Parametric\bin\parametric.exe" worked for me.

    Friday, January 24, 2014 9:18 PM
  • I'm trying the following in single bat file named as MAIN.dat:

    start cmd /k call run1.bat
    start cmd /k call run2.bat
    start cmd /k call run3.bat
    start cmd /k call run4.bat

    and each bat file contains mstsc command to some server as follows:

    run1.bat contains mstsc -v server1

    run2.bat contains mstsc -v server2

    run3.bat contains mstsc -v server3

    run4.bat contains mstsc -v server4

    Whenever I run MAIN.dat it opens multiple cmd prompts and never exists automatically.

    Is there any way to close them automatically when my mstsc command successfully connected to the required server ?

    I tried putting the exit after mstsc command as follows:

    mstsc -v server3

    exit

    but it never reaches to exit as mstsc -v server3 seems to be waiting for some status.

    Any help will be appreciated.

    Thanks much in advance.

    Monday, October 12, 2015 10:05 PM