In Firefox, Using Imacros, I would like to launch multiple macros from a batch file but here is the problem: I want them to run one by one. So first 'Macro 1' will run then after it completes, 'Macro 2' will run and so on till 'Macro 7'.
My BATCH CODE:
cd C:\Program Files\Mozilla Firefox
start firefox.exe
ping -n 05 127.0.0.1>nul
start firefox.exe imacros://run/?m=NAMEofMACRO.iim
Imacros VERSION BUILD=7601105
Just change your macro line to use the start switch /wait
start /wait firefox.exe imacros://run/?m=NAMEofMACRO.iim
start /wait firefox.exe imacros://run/?m=NAMEofNextMACRO.iim
start /wait firefox.exe imacros://run/?m=NAMEofNextMACRO.iim
That will launch each one, wait for it to finish, then start the next.
Another way, inside imacros, is to add at the and of each macro.iim the line
URL GOTO=imacros://run/?m=NAMEofNextMACRO.iim
So you have to run just the first macro; this macro, at the end will call the second, and the second, at the end, will call the third, and so on...
Related
I have a batch file which launches let's say 10 applications one after the other.
It waits till the launched application finishes and then proceeds to next one. There is no problem here.
However I am unable to capture (in the batch file) the console output which each of the 10 called applications produce.
Below is what I am talking about:
start /wait ./TestApp1/Debug/TestApp1.exe
start /wait ./TestApp2/Debug/TestApp2.exe
start /wait ./TestApp3/Debug/TestApp3.exe
start /wait ./TestApp4/Debug/TestApp4.exe
start /wait ./TestApp5/Debug/TestApp5.exe
start /wait ./TestApp6/Debug/TestApp6.exe
start /wait ./TestApp7/Debug/TestApp7.exe
start /wait ./TestApp8/Debug/TestApp8.exe
start /wait ./TestApp9/Debug/TestApp9.exe
start /wait ./TestApp10/Debug/TestApp10.exe
Lets say each of the TestApp generate some output.
I want to consolidate all of them into one text file.
Any pointers on how to achieve this?
I would suggest you first of all try it without the Start command:
#(
"TestApp1\Debug\TestApp1.exe"
"TestApp2\Debug\TestApp2.exe"
"TestApp3\Debug\TestApp3.exe"
"TestApp4\Debug\TestApp4.exe"
"TestApp5\Debug\TestApp5.exe"
"TestApp6\Debug\TestApp6.exe"
"TestApp7\Debug\TestApp7.exe"
"TestApp8\Debug\TestApp8.exe"
"TestApp9\Debug\TestApp9.exe"
"TestApp10\Debug\TestApp10.exe"
) > "logfile.txt"
If you really do need that Start command, then similarly:
#(
Start "" /Wait "TestApp1\Debug\TestApp1.exe"
Start "" /Wait "TestApp2\Debug\TestApp2.exe"
Start "" /Wait "TestApp3\Debug\TestApp3.exe"
Start "" /Wait "TestApp4\Debug\TestApp4.exe"
Start "" /Wait "TestApp5\Debug\TestApp5.exe"
Start "" /Wait "TestApp6\Debug\TestApp6.exe"
Start "" /Wait "TestApp7\Debug\TestApp7.exe"
Start "" /Wait "TestApp8\Debug\TestApp8.exe"
Start "" /Wait "TestApp9\Debug\TestApp9.exe"
Start "" /Wait "TestApp10\Debug\TestApp10.exe"
) > "logfile.txt"
If your application requires the use of Start, then you would be well advised to take a look at its usage information, (options such as /B may also be needed).
Please note, that I've included doublequotes, such that the script can be used as a template for others, without worrying about problematic characters, and I've also used the correct path separators for Windows, i.e. the back slash.
bat files from another Main.bat file
Files contain something like follows and i want both to launch in 15 seconds delayed and stay untill i close each one of them with a "Ctrl+C", can someone please help me with this Use Case please.
Main.bat
echo Task-1:
call C:\Users\user\bat\My_bat1.bat
echo Task-2:
call C:\Users\user\bat\My_bat2.bat
My_bat1.bat
start /wait cmd.exe /k "cd PATH && mvn -P dev"
My_bat2.bat
start /wait cmd.exe /k "cd PATH && mvn -Dspring.profiles.active=dev,swagger,no-liquibase -Dspring.cloud.config.profile=dev -DskipTests=true"
If you are just asking how to delay your batch files by 15 seconds you can do it like this:
choice /t 15 /D y /n
If not can you please clarify your question?
EDIT: Based on your update, you want to add pause to your first child bat file, then the code above before the call command in your parent bat file.
You should really edit your question to include the sequence of events you want from the comments because it causes a lot of confusion.
I'll try to piece together what you want:
Start job 1, creating a new window
Do not wait for job 1 to finish, instead wait 15 seconds
Start job 2, creating a new window
If you press Ctrl+C in either window it should stop the job and close the window
I assume that if one job is terminated before or after the other is started, the other still needs to start or continue to work.
First of all, the program that currently runs - in your case that seems to be maven - actually receives Ctrl+C and decides how it wants to act on it. I'm not sure if it does in the way you want it to.
Main.bat
echo Task-1:
"%comspec%" /c "C:\Users\user\bat\My_bat1.bat"
timeout 15 /nobreak
echo Task-2:
"%comspec%" /c "C:\Users\user\bat\My_bat2.bat"
I added a timeout command between the launches. It waits 15 seconds.
If you removed /nobreak it would also be possible to interrupt the wait with a keystroke launching task#2 early
I find that call sometimes introduces wierd errors in such cases so I prefer "%comspec%" /c. It does the same thing except it does not receive back environment variables set in child file which is fine in your scenario.
My_bat1.bat
start "" "%comspec%" /c "cd PATH & mvn -P dev & timeout -1 /nobreak"
I removed /wait which prevented the second mvn instance from starting until the first one is finished or terminated.
I replaced /k with /c and added timeout to pause execution in stead of /k.
The timeout -1 /nobreak statement causes command interpreter to wait indefinitely without a chance to stop it except for Ctrl+C.
You can remove /nobreak to allow it to be closed with any keystroke if mvn exited normally (if that ever happens)
"%comspec%" is the same as cmd.exe but is preferred if Microsoft ever decides to change command interpreter exe name. Empty "" before is required because start interprets first double-quoted string as a window name.
I assume there is a folder named PATH inside current folder because it is not a variable. Furthermore, variable %PATH% is reserved for executable/library search path list and must not be assigned some random value or used with cd command unless you really know what you are doing. See path /?.
I also used & instead of && to prevent window from closing if mvn crashes.
My_bat2.bat can be changed similarly.
I'm currently working on a batch file that should download files via their URL and them run formatting script on them however I don't know how to to delay the batch-file during downloading, however since it's a direct download the window doesn't stay open.
here's where I'm at :
START "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
MOVE C:\\Users\\*\\downloads\\*.csv %~dp0
EXIT
I would like to wait for the first line to finish before continuing.
Thanks for your consideration
From cmdline (cmd.exe) run start /? and you will find some help. There is a specific line in the help file for the /wait switch which reads:
WAIT Start application and wait for it to terminate.
So simply start chrome with the /wait switch:
Start /wait "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
As per your comment, the above will not work. It is probably best to test if the file exists, chrome will have a .crdownload extension when still downloading. So let's test that the *.csv.crdownload does not exist.
start /wait "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
:hold
timeout 5
if /i not exist *.csv.crdownload (MOVE "C:\\Users\\*\\downloads\\*.csv" %~dp0) else ( goto :hold)
exit
What I got is a list of bat files:
file1.bat
file2.bat
…
file29.bat
I need them to run one after each other. Meaning when the file1.bat closes file2.bat starts and so on.
I tried this, but it doesn't work properly:
start /wait call file1.bat
start /wait call file2.bat
You might want to add more to your question to make it easier to understand. My guess is that you want the bat file to open the next one then close itself after that.
If that's what you want to do; add these commands to each of the files:
start file2.bat
exit
Of course, you'll want to change start file2.bat to start file3.bat and so on for each file.
If you want file1.bat to manage all of the files, I don't think that's possible in batch.
You didn't describe how exactly it's not doing what you expected. I'm guessing that what happens is you're having to shut down each script before the next one will continue.
Documentation on start says:
WAIT Start application and wait for it to terminate.
command/program
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.
If you must use start then you could force it to use the /c switch which will automatically close the window once it's done:
start /wait cmd /c call file1.bat
I'm not really sure you accomplish anything by using call so that ought to be equivalent to just:
start /wait cmd /c file1.bat
Using start creates a new window for each program and you may just want to have it all run in a single command processor window.
As noted by Biffin you can just list them all out in a master script and they will run in order.
call file1.bat
call file2.bat
...
call file29.bat
And a shorthand for that is:
for /l %%f in (1; 1; 29) do call file%%f.bat
Remember to double up those percent characters inside a batch script but not on the command line.
This question might explain some of the unexpected behavior you were seeing.
How to run multiple .BAT files within a .BAT file
As the title says what parameters would you use in a batch file to continually execute a command e.g.
start notepad
loop
Another option in a single line (which will also work from the command line):
for /l %x in (1,0,2) do (start /wait notepad)
If you're using that in a batch file, use
for /l %%x in (1,0,2) do (start /wait notepad)
instead.
Use goto:
:loop
start /wait notepad
goto loop
Note that I have used start /wait here. If you don't do that, your batch file won't wait for notepad to exit, and you'll start a zillion notepads and probably eventually crash.