Solved

how to run list of commands at command line at the same time

Posted on 2011-03-03
22
397 Views
Last Modified: 2012-05-11
Hi,

I have  a list of commands to run (may be around 150). I can run them one by one without any issues. But i want to run them all at once and want to copy the results.

e.g.

collection-admin -m viewcollection -n SCO
collection-admin -m viewcollection -n NHSSLelib
collection-admin -m viewcollection -n NHSDogsPharm
collection-admin -m viewcollection -n Show
collection-admin -m viewcollection -n OnlineBorders
collection-admin -m viewcollection -n carecommission
collection-admin -m viewcollection -n SCCJR
collection-admin -m viewcollection -n NHS24

each single line above is command and shows me result but how can i run all at once?

Thanks
0
Comment
Question by:mmalik15
  • 10
  • 6
  • 3
  • +2
22 Comments
 
LVL 14

Expert Comment

by:John-Charles-Herzberg
ID: 35025918
Have you looked into Autoit v3?

How is your review of the credit cards going?  I think we need to make a decision today on what we need to do with the remaining cards.

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages. AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35025920
Easiest way would be just to put them all into a batch file. The you only need to execute the batch file rather than each command individually.
0
 

Author Comment

by:mmalik15
ID: 35025957
thanks for the comments. In this case the commands dont have a carriage return

i  have copied pasted the above commads at the DOS  and i only get the result of the last command. e.g.

when i run the following command  i only get the result of


collection-admin -m viewcollection -n SCO
collection-admin -m viewcollection -n NHSSLelib
collection-admin -m viewcollection -n NHSDogsPharm

of this command. which is the last one in the list

collection-admin -m viewcollection -n NHSDogsPharm
0
 

Author Comment

by:mmalik15
ID: 35025973
I have just created a batch file with the above commands and run it
i am only getting the result of the first command i.e.

collection-admin -m viewcollection -n SCO
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35025977
If you put all those files in a batch file (say test.bat for example) and then run:
test.bat

Open in new window

From a command line you should see the output of each command. You might have to scroll up the cmd window because it will execute and display the output for each command in turn.
0
 
LVL 5

Expert Comment

by:boing40001
ID: 35025993
i think you just copied pasted in the command prompt. you should use a batch file instead like the attached one (rename it bat1.bat before use)

bat1.bat.txt
0
 
LVL 5

Expert Comment

by:boing40001
ID: 35026006
i did'nt read your own answer before replying...
do you get any error message from the other commands?
0
 

Author Comment

by:mmalik15
ID: 35026017
thanks boing

I have created exactly the same file but i am getting result of the first command :(
0
 

Author Comment

by:mmalik15
ID: 35026026
no i dont get any errors. The batch file runs and just returns me the output of the first line
0
 
LVL 5

Expert Comment

by:boing40001
ID: 35026038
why don't you add some pause command between lines?
0
 

Author Comment

by:mmalik15
ID: 35026050
Tried pause but still no difference
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:boing40001
ID: 35026098
but afer the first command, it should now pause and tell you something...still no error or something else?
0
 

Author Comment

by:mmalik15
ID: 35026137
nothing else this is how i am running batch file(sample file as you attached above) and this is what i am getting

C:\>a.bat

C:\>collection-admin -m viewcollection -n SCO
Name:        SCO
Valid:       yes
Description: http://www.scie-socialcareonline.org.uk/
Cluster:     webcluster
Pipeline:    SCOPipeline (webcluster)
Datasource:  fastuat1.scot.nhs.uk:14000

C:>
0
 
LVL 5

Expert Comment

by:boing40001
ID: 35026198
can you try to put the following commands in the batch file and see what happens?

start cmd /k collection-admin -m viewcollection -n SCO
start cmd /k collection-admin -m viewcollection -n NHSSLelib
start cmd /k collection-admin -m viewcollection -n NHSDogsPharm
start cmd /k collection-admin -m viewcollection -n Show
start cmd /k collection-admin -m viewcollection -n OnlineBorders
start cmd /k collection-admin -m viewcollection -n carecommission
start cmd /k collection-admin -m viewcollection -n SCCJR
start cmd /k collection-admin -m viewcollection -n NHS24
0
 

Author Comment

by:mmalik15
ID: 35026233
thanks for the comments boing

its running all the commands now but in cascading command line windows i.e. one result per window . Is it possible to get the result in just one window
0
 
LVL 5

Expert Comment

by:boing40001
ID: 35026249
usually batch file run commands one line at a time, in only one window. In your case i don't know why this is not happening. the last test i proposed you was just to verify the correct behaviour of batch files in your environment.
I'm going to lunch now :)
0
 

Author Comment

by:mmalik15
ID: 35026274
oh okay boing

Enjoy your lunch :)
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35026353
why don't you do the folowing

Create the Batch file of Boing
but add the folowing after every command
>> Output.txt

This will send the output to that Output.txt file

At the end of the batchfile add the folowing lines toprint the output.txt upon the screen
@echo off
for /f "usebackq delims=" %%a in (Output.txt) do (
  echo %%a
)

delete the output.txt
del/Q Output.txt

So it becomes :
start cmd /k collection-admin -m viewcollection -n SCO >> output.txt
start cmd /k collection-admin -m viewcollection -n NHSSLelib  >> output.txt
start cmd /k collection-admin -m viewcollection -n NHSDogsPharm >> output.txt
start cmd /k collection-admin -m viewcollection -n Show >> output.txt
start cmd /k collection-admin -m viewcollection -n OnlineBorders >> output.txt
start cmd /k collection-admin -m viewcollection -n carecommission >> output.txt
start cmd /k collection-admin -m viewcollection -n SCCJR >> output.txt
start cmd /k collection-admin -m viewcollection -n NHS24  >> output.txt
@echo off
for /f "usebackq delims=" %%a in (Output.txt) do (
  echo %%a
)
del/Q Output.txt


regards
poor beggar
0
 

Author Comment

by:mmalik15
ID: 35026397
Thanks sir this is i get after making your suggested changes

C:\>a.bat

C:\>start cmd /k collection-admin -m viewcollection -n SCO  1>>output.txt

C:\>start cmd /k collection-admin -m viewcollection -n NHSSLelib  1>>output.txt

The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n NHSDogsPharm  1>>output.t
xt
The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n Show  1>>output.txt
The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n OnlineBorders  1>>output.
txt
The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n carecommission  1>>output
.txt
The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n SCCJR  1>>output.txt
The process cannot access the file because it is being used by another process.

C:\>start cmd /k collection-admin -m viewcollection -n NHS24  1>>output.txt
The process cannot access the file because it is being used by another process.
The system cannot find the file Output.txt.

C:\>
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35026487
some copy paste issues :

I've replaced at my side by the dirs ;-)

should have been :
 
@echo off
start cmd /C "dir c: >> output1.txt"
start cmd /C "dir c: >> output2.txt"
start cmd /c "dir c: >> output3.txt"
start cmd /c "dir c: >> output4.txt"
start cmd /c "dir c: >> output5.txt"
start cmd /c "dir c: >> output6.txt"
start cmd /c "dir c: >> output7.txt"
start cmd /c "dir c: >> output8.txt"
pause



for /f "usebackq delims=" %%a in (Output1.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output2.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output3.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output4.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output5.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output6.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output7.txt) do (
  echo %%a
)
for /f "usebackq delims=" %%a in (Output8.txt) do (
  echo %%a
)
del/Q Output*.txt

Open in new window


the Why's


1) if the command gives a return value the command stops : thats why the normal way doesn't work

2) start cmd / C starts a new command and executes the command
3) using the >> outputX.txt writes the output into the NEW file ==> therefore the numbers  ;-)

4) we must pause until all commands are done to read the files.
5) we cleanup our mess and delete the outputfiles

regards

poor beggar
0
 

Author Comment

by:mmalik15
ID: 35026596
Thanks for the detailed explination sir.

Can we not write and append the information into an existing file rather then creating a new file every time as i have hunderds of file and the process wont be very efficent if i create hunderds of dir. or is there a command to close the opened output.txt file so that it gets opened everytime we want to add new text into it.

0
 
LVL 10

Accepted Solution

by:
John Claes earned 500 total points
ID: 35027016
I've done the folowing

I've rerouted all to the output.txt
I've added after every Start line an Choice. This gives the user 0 sec to answer with a X before we give the answer.
This ensures that the program waits before starting the other start (otherwise the overwrite eachother files)

 
@echo off
start cmd /C "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /C "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls
start cmd /c "dir c: >> output.txt"
Choice /C:x /N /T 0 /D x
cls

pause

for /f "usebackq delims=" %%a in (Output.txt) do (
  echo %%a
)
del/Q Output*.txt

Open in new window


regards
poor beggar
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now