Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch problem - total noob.

    I have a batch program which asks for some input, stores it in a variable, and uses it throughout.

    Problem is, whenever I run it through double clicking it instead of at the prompt, it closes after I give it the input. This has also happened with several PAUSE commands.

    How can I work around this, making it finish the entire program even when not run at the prompt?

    It's similar in functionality to this:

    Code:
    @echo off
    ECHO What is your name?
    SET /p name=
    ECHO Welcome %name%!
    Thanks in advance!
    The Devil sold his soul to Bill Gates.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    The problem is not with the batch file, it's how you're executing it. Your batch file is actually completing and then the window closes. In order to execute by "double clicking" and keep the window open after the batch file completes, you need to pass the batch file as a parameter to cmd. The easiest method would be to create a shortcut to cmd and pass your batch file in the command.

    Assuming your batch file is named name.bat and is in C:\batch directory, the target for the shortcut would be:
    %windir%\system32\cmd.exe /k C:\batch\name.bat


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •