Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

file1.txt:

notepad
wordpad

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

share|improve this question
    
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

3 Answers 3

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
share|improve this answer
    
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
setlocal
set OK=N

:again
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.
endlocal
goto end


1: start notepad

2: start wordpad

:end
@echo on
cls
share|improve this answer
    
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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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