- 1 year ago
Windows Command line : start blocking task which opens a window, ask that window to get focus
You can achieve this by using the start
command with the /b
option to run the blocking task in the background, and then use the timeout
command to wait for a few seconds to allow the window to fully open, and finally use the taskkill
command with the /f
and /im
options to force close any existing instances of the window and then bring the new window to the foreground.
Here's an example command that you can modify to fit your specific use case:
bashstart /b my_blocking_task.exe
timeout /t 3
taskkill /f /im my_blocking_task.exe
start "" /b my_blocking_task.exe
In this example, my_blocking_task.exe
is the name of the executable file for your blocking task. The first start
command runs the task in the background, the timeout
command waits for 3 seconds to allow the window to fully open, the taskkill
command kills any existing instances of the window, and the second start
command opens a new instance of the window in the foreground. Note that the ""
after the start
command is required to specify an empty window title.