How do I obtain the currently running batch file’s PID? If you’ve installed the Microsoft Windows NT Resource Kit, you can use the following batch file to obtain the currently running batch file’s process identifier (PID). To use this script at the command line, change the double percentage sign to a single character (i.e., %). for /f "Tokens=*" %%I in ('f:\tlist ^| grep %0 ^| grep CMD ^| awk "{ print $1 }"') do call :SETPID %%I :next ....... :SETPID set MASTER_PID=%1 goto :next ....... The following alternative uses the resource kit’s Tlist utility. for /f "Tokens=1 Delims= " %I in ('c:\tlist ^| find "%0"') do goto :SETPID %I :next ....... :SETPID set MASTER_PID=%1 goto :next ....... Use the command tlist rather than pulist, because pulist doesn’t give enough information. You need the batch file’s name, which tlist provides. Because the shell uses the pipe character (i.e., |), you must use the caret character (i.e., ^) to escape the pipe. You can compile the tlist alternative on one line, as follows. for /f "Tokens=1 Delims= " %I in ('c:\tlist ^| find "%0"') do set MASTER_PID=%1 ----------------------------------------------------------------------------- :_filecheck if exist e:\upload\file.txt goto _actionfile sleep 100 goto _filecheck :_actionfile Variation: This batch file checks for the file file.txt every 100 seconds. You might run into problems if the file is large and is still under construction when the batch file looks for the file (e.g., if the file is transferring over an FTP link and is still writing). To solve this problem, rename the file to itself, as the following command shows. RENAME e:\upload\file.txt file.txt if not errorlevel 0 goto _actionfile The rename command generates an error message if the file doesn't exist or isn’t available to write to (e.g., because it is still being written to). The errorlevel is the same, but the error message changes, in case you want to distinguish between the two in the .bat file. ----------------------------------------------------------------------------- When Windows NT batch file processing encounters the goto command, the process ignores lines in the batch file until it finds the appropriate goto label. :_beg @echo off goto _mod BATCHFILE.BAT v1.01 - does what batch files do written 09/09/1999 by Joe Programmer MODIFICATION HISTORY: v1.00 09/04/1999 jp initial version v1.02 09/09/1999 jp converted all dates in comments to four-digit years for Y2K compliance :_mod ... :_end