How to Detect if a Winbatch Script was Launched from DOS Console
Keywords: Detect DOS Console
Question:
Can a WinBatch script be made aware of how it was launch, e.g. via "Start -> Run" or via a console window on WinNT (or a DOS window on Win9x)?I have a situation where a .BAT file is being run and it makes use of some compiled WinBatch scripts. To keep everything running synchronously, the "START /W" or "START /WAIT" command is being used to force the .BAT file to pause until the compiled WinBatch script has completed.
What I would like to be able to do is to have WinBatch be aware of the fact that it was launched "synchronously" via a console/DOS window have it be able to interact with the user via stdin/stdout/stderr in the console/DOS window.
Answer:
You could just have a flag file in your BAT file where you could...echo CONSOLE MODE > c:\console.txt start /w compiled.exe del c:\console.txtAnd WinBatch could do a FileExist on the console.txt file to see if maybe it was launched from the BAT file.
Article ID: W12890Filename: How to Detect if a WBT was Launched from DOS Console.txt