0

I want to run a command that opens a blocking window, but since that window won't come to focus (and thus come out in front of all other windows) I'd like to tell it to do that.

However if I run :

 <blocking command> & <command to request focus>
 <rest of script>

this runs in parallel i.e. the <command to request focus> will execute without waiting for <blocking command> and then <rest of script> will immediately run.

This is bad for me because it looses the blocking effect. This is important to me, as the blocking command holds a temporary file which I need to delete in <rest of script> after <blocking command> has released it).

I tried to marry the following two approaches :

  1. Script to request focus which is composed of three subcommands (and I do not want this in a separate file because some of these subcommands depend on the value of local variables)

  2. Script to launch two commands in parallel and wait on all which offers to run a block in parentheses of start commands and waits on the end of the block.

     (
         start qtcreator.exe -block "$tmp"
         start echo (new ActiveXObject("WScript.Shell")).AppActivate("$tmp"); > focus.js ; cscript //nologo focus.js ; del focus.js
     ) set -P "="
     rm "$tmp";
    

The problem is I think : 1. is composed of multiple commands and 2. uses start : and it seems that start is supremely unhappy with multiple commands (indeed, it is hard to parse out when another command that start needs to run begins, or when the start command itself is finished).

I am also fully aware that when running in parallel, nothing promises me that my app will have opened its window as per the first command before window focus is requested as per the second command, but this is okay in my use case, and at worst I can implement a small waiting thing. I just want to know how to run those two things in parallel if they are more than just single commands, in a way that does not require of me to have batch files every where that are called (to hide the complexity).

Any suggestions ? Either for a command that nicely does both (open my blocking window and requests focus) or on how to run two commands in parallel ?

Charles
  • 988
  • 1
  • 11
  • 28
  • Please note that the internal command `start` of `cmd.exe` is for calling the Windows kernel library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with a filled [STARTUPINFO](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow) structure to create a new process for an executable running parallel to `cmd.exe` processing the batch file and with a new console window if the executable is a Windows console application. – Mofi Feb 20 '23 at 17:37
  • 1
    `echo` is an internal command of `cmd.exe` and not an executable. It is not possible for that reason to run as parallel task `echo`. It would be necessary to run `%ComSpec% /D /C echo ...` or `%ComSpec% /D /S /C "echo ..."` to execute one more `cmd.exe` to execute its internal command `echo`. The usage help of `cmd.exe` output on running `cmd /?` in a command prompt window explains how `cmd.exe` interprets the argument(s) after option `/C` (run command line and Close) or option `/K` (run command line and Keep running). – Mofi Feb 20 '23 at 17:40
  • Excellent piece of info there about `echo`. I think I'm going too deep down a rabbit hole for a simple thing. Any other suggestion to both keep qt creator blocking while requesting it to come in focus ? – Charles Feb 21 '23 at 09:40

0 Answers0