I need help with this statement at the moment when executed in a batch file it will launch all lines of a text file e.g.



so it will launch:

start notepad
start wordpad

Although I would like to be able to specify which line it will execute, instead of executing them all (which it is doing at the moment)

for /f "delims=|" %%i in (file1.txt) do @start "x" %%i

  • This isn't very clear, do you want an interactive method of choosing which line in the batch file gets executed? – phuzion May 13 '11 at 18:48
  • @phuzion My apologies, yes it does have to be interactive – Peter Manton May 13 '11 at 18:55
  • Can you elaborate on why you want to do this? The use case is going to affect how to go about solving this problem. My main issue with this is that you seem to be asking for a batch file that will parse a file and provide the user with programs to run. A batch file is probably the worst tool for this task. Are you in a restricted environment that forces you to use this technology? – Doltknuckle May 13 '11 at 19:06
  • Hi, yes I am in a restricted enviroment, as you can imagine its not the easiest thing to do using batches, quite frustrating. But I have gone and used another way of doing it now, so this question can be closed if needs be. – Peter Manton May 13 '11 at 20:19

I’m not sure what you want (or what the problem is), but it reads like you need to use the /w switch of the start command:

for /f "delims=|" %%i in (file1.txt) do @start /w "x" %%i
  • Hi, I mean, if I specify line number 2 of the text file (wordpad) it will launch wordpad. (Nothing else) – Peter Manton May 13 '11 at 18:50

Here is a batch file that will allow you to choose between the two options:

echo off
title Notepad or Wordpad
set OK=N

set /p choice=Please enter:    1 [Notepad],    2 [Wordpad]
if [%choice%]==[] goto again
if [%choice%]==[1] goto 1
if [%choice%]==[1] goto 2
set /p xxx=wrong entry, press any key to return.
goto end

1: start notepad

2: start wordpad

@echo on
  • Hi, sorry, but the problem is that I am calling the lines from a text file, and they are variable – Peter Manton May 13 '11 at 18:53
  • Ahh, I see. Sorry, I misread your question :-) – Amartel May 13 '11 at 19:37

Just copy the .txt file to new_batch_file.bat then use the following command to call it:

  • CALL new_batch_file.bat

How about this?


# Comments and empty lines are ignored

# Lines starting with a hyphen '-' indicate a group
- Editors
1 Notepad.exe
2 WordPad.exe

# You can use numbers or letters, and even words (without spaces)
- Graphics
P mspaint.exe


@echo off

if not exist ".\dir.menu" echo There is no "dir.menu" file in the current directory. & goto :end

set arg=%~1

if not defined arg goto :show_menu

for /f "tokens=1,* delims= " %%i in (dir.menu) do (
    if not "%%i"=="#" if /i "%arg%"=="%%i" (
        start "x" "%%j"

    exit /B

    echo   Menu:
    echo ===================
    for /f "tokens=1,* delims= " %%i in (dir.menu) do (
        if not "%%i"=="#" (
            if "%%i"=="-" (
                echo   %%j
            ) else (
                echo    %%i] %%j
    goto :end

This is a simple, but nice menu system. You can use numbers or letters (or a word, without spaces) as the key. I've kept it very simple so you can see how to interact with it. (For instance, you could create a set of directories as a whole menu system, where the menu items are all inside 'dir.menu' files.)

Sample usage:

   1] Notepad.exe   
   2] WordPad.exe   
   P] mspaint.exe   

>menu p
[mspaint is launched]

UPDATED: tested and corrected a couple things from my computer, instead of my phone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.