Start a ConEmu tab with a delay - conemu

I'm trying to set up a task in ConEmu to start a Mongo DB server, wait few seconds and start a new ConEmu tab with a Mongo client.
My current ConEmu configuration looks like this:
> cmd /k C:\bin\MongoDb2.6\bin\client-delay.bat
cmd /k C:\bin\MongoDb2.6\bin\mongo-start.bat -cur_console:s25H
The client-delay.bat script is using the timeout.exe command to create delay.
Is there a way to add a delay in ConEmu directly instead of using timeout command?
Thanks!

There is general tab creation timeout setting, but it affects all possible tasks. Almost useless in your case and you'll lose ability to cancel waiting. Option was created for debug purposes.
Why do not to use timeout in the task itself?
> cmd /k C:\bin\MongoDb2.6\bin\client-delay.bat
cmd /k timeout 10 & C:\bin\MongoDb2.6\bin\mongo-start.bat -cur_console:s25H

Related

I want to launch 2 .bat files from another .bat file

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.

Best batch practice to run a second command with &&

i'm looking for best practice in a situation where i want to send two commands to a separate window. as in:
start /wait command1 && command2
this works however the second command is not executed in the new window instead runs in the initial window after the first task is finished.
how should a situation like this be handled correct?
You cannot do it directly with start but cmd supports that using quotes:
start /wait cmd /c "command1 && command2"
You probably can use cmd directly:
cmd /c "command1 && command2"

Go to the link every 10 minutes

I would like to go to a certain link every 10 minutes. I did a batch file to run an IE instance with path specified:
start /d iexplore.exe http://dbmsportal/generateXML.php
Task completes well, but the problem is Task Scheduler creates a new instances of iexplore each time.
I am new in a CMD commands could someone suggest me how to regularly proceed bat file within one instance. Maybe I have to kill the process each time?
This is a VBS script. Alter it to suit.
The LocationName is the title bar text (which is hidden in current versions of windows. I've thrown a msgbox in to display it. Delete the line when you find it.
Set objShell = CreateObject("Shell.Application")
Do
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
If window.locationname = "website1.com" then
window.refresh2 3
End If
Next
Wscript.sleep 5000
Loop
Ive come up with scheduling another process that kills All iexplore processes each hour:
taskkill /F /IM iexplore.exe
I know this is not a good solution, but I don't have time to learn VBS.
Make it a hidden window and add this on a new line before the code you currently have:
:openLink
timeout /T 600 >nul
and after the line of code you currently have add this:
goto :openLink

Start cmd with pre-loaded string

I would like to know if it is possible to start cmd.exe from a .bat file, having a string pre-loaded but witout executing it immediately.
So effectively what i want to do is to have a bat like the below:
cmd /K time
but when the user double-clicks on it to just show the:
C:\Windows\time
but without executing it. I would like the user to press "Enter" to run it.
Is there an option in cmd.exe that allows that?
Thanks.
cmd /k "set /p cmd=C:\Windows\time&time"
if this isn't what you were looking for could you please describe what you are trying to accomplish?

Start multiple console apps from a batch file

I'm trying to run some console application .exe files from a batch file in Windows.
However, when I run the following code it only starts the first of the apps:
"C:\Development\App\bin\Debug1\Application.exe"
timeout 5
"C:\Development\App\bin\Debug2\Application.exe"
timeout 5
"C:\Development\App\bin\Debug3\Application.exe"
timeout 5
"C:\Development\App\bin\Debug4\Application.exe"
timeout 5
"C:\Development\App\bin\Debug5\Application.exe"
timeout 5
(I've included the timeout to spread out the intial processing a bit)
Is there a way to get the script file to start the first application, then move on and start the others?
Ideally I would like the script file to start all applications in a subdirectory, so that if I had Debug\Applications\*.exe or similar it would start all applications of type .exe (and possibly waiting 5 seconds between each). Is this possible?
You can start applications in the background by using start:
start "C:\Development\App\bin\Debug1\Application.exe"
Use start /? from a command window to get further details.
For example,
start dir
will open a new command window and show you a directory listing, leaving it open when finsished.
The:
start cmd /c "ping 127.0.0.1 && exit"
command will open a new window, run a four-cycle ping on localhost then exit.
In both cases, the current window will await the next command immediately.
#echo off
for %%F in ("Debug\Applications\*.exe") do (
start "" "%%F"
timeout 5
)

Resources