Link to home
Start Free TrialLog in
Avatar of mmalik15
mmalik15

asked on

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

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
Avatar of John-Charles-Herzberg
John-Charles-Herzberg
Flag of United States of America image

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.
Avatar of Carl Tawn
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.
Avatar of mmalik15
mmalik15

ASKER

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
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
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.
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
i did'nt read your own answer before replying...
do you get any error message from the other commands?
thanks boing

I have created exactly the same file but i am getting result of the first command :(
no i dont get any errors. The batch file runs and just returns me the output of the first line
why don't you add some pause command between lines?
Tried pause but still no difference
but afer the first command, it should now pause and tell you something...still no error or something else?
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:>
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
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
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 :)
oh okay boing

Enjoy your lunch :)
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
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:\>
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
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.

ASKER CERTIFIED SOLUTION
Avatar of John Claes
John Claes
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial