DETACH
[/?]
[/N/C/K]
command
[arguments]
/?/N/C/KThe DETACH command runs command "detached", i.e. in the same session as the process that invoked DETACH but without being attached to the session's console. command is run by spawning a detached command interpreter process passing command and arguments as its command line arguments. This allows command to be a built-in command or a script if desired.
The process is spawned asynchronously, and may continue running after the DETACH command itself has exited. DETACH prints the ID of the command interpreter process that it spawns to its standard output.
DETACH stops processing its command line at the first non-option argument that it reaches. The remainder of the command line from that point onwards is passed verbatim to the command interpreter.
If the /C option is used, the name of the command interpreter is taken from the value of the COMSPEC environment variable, and a /C option is prepended to the command line that is passed by DETACH to the command interpreter, telling the command interpreter not to enter interactive mode once it has finished processing its command line (if any). If the COMSPEC environment variable does not exist, DETACH will fall back to using the name "CMD" for the non-interactive command interpreter.
If the /K option is used, the name of the command interpreter is taken from the value of the OS2_SHELL environment variable, and a /K option is prepended to the command line that is passed by DETACH to the command interpreter, telling the command interpreter to enter interactive mode once it has finished processing its command line (if any). If the OS2_SHELL environment variable does not exist, DETACH will fall back to using the COMSPEC environment variable for the name of the interactive command interpreter, or "CMD" if that environment variable also does not exist.
If neither the /K nor the /C option is used, nothing is prepended to the command line that is passed by DETACH to the command interpreter. The assumption is that the command interpreter will follow the convention of entering interactive mode by default, so the name of the interactive command interpreter is determined in the same way as if the /K option were used.
Note: Always use an explicit /C or /K option if OS2_SHELL (or COMSPEC, if OS2_SHELL does not exist) points to the 16-bit CMD supplied with IBM OS/2. The 16-bit CMD supplied with IBM OS/2 contains a feature inherited from COMMAND on MS/PC-DOS version 2.0 whereby unless it is passed an explicit /C or /K option the first argument on its command line is taken to be a directory name. Considering the reasons for its existence on DOS, which are to do with reloading "transient" code and data into memory, this feature has absolutely no use, and no reason for existence in an OS/2 command interpreter. It should never have been included in the 16-bit CMD supplied with IBM OS/2. The only reason that it cannot be considered an outright bug is that IBM documents it. In any case, when the DETACH command is not given an explicit /C or /K option, it will not pass an explicit /C or /K option to the command interpreter that it spawns. With the 16-bit CMD supplied with IBM OS/2 this will cause unexpected behaviour. Neither TEXTCMD nor JP Software's 4OS2 contain this needless, pointless, useless, and downright silly relic of MS/PC-DOS version 2.0. For best results, set OS2_SHELL to point to either one of them, rather than to the 16-bit CMD supplied with IBM OS/2.