Solved Applet Needed - Wait for Program to Start

September 15, 2016 at 23:22:19
Specs: XP Pro_SP3
I create scripts for my business. They're needed because automating repetitive or
complex processes saves me hundreds of hours. However, I am not and will never
be a full-blown programmer!

I have several scripting apps, but they all lack a command that I need to complete
a script. Instead of the usual "Wait for Program" I need "Wait for Program to Start."
"Wait for Program" is always used after "Run Program." It waits (indefinitely, if needed)
for a program to terminate before continuing. I've tried using a few inverse logic
functions like an "If(Not)" before a "Wait for Program." The apps I use are not that
flexible. The script will just stop or produce an error message.

I need a single purpose command applet like these at F2K0 that will wait (indefinitely,
if needed) for a specified program to start:

If you're a "real" programmer please don't suggest a complex solution I will never be
able to use. I must work within the limits of the scripting apps I've used for years.

I found F2K0 while performing a Google search. There must be a few million command
collections similar to F2K0. I hope you can help me find what I'm searching for.

See More: Applet Needed - Wait for Program to Start

Reply ↓  Report •

September 16, 2016 at 01:20:00
Why use 3rd party software when you can just create a loop that checks if the process is running?

tasklist /FI "imagename eq PROGRAM.EXE" 2>nul | find /i /n "PROGRAM.EXE">nul
if %errorlevel%==0 (
        goto :continue
goto :loop

(Of course, replace PROGRAM.EXE with the executable you're waiting for.)

If this is too complex, allow me to explain.

It lists all processes running that matches the "imagename" you have provided. Which would be PROGRAM.EXE, it then tries to find the name of the given proceess in the output of the tasklist command, if it finds the name it means the process is running.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ

Reply ↓  Report •

September 16, 2016 at 21:54:05
Thank you for replying RainBawZ.

Most people don't create scripts, but almost everyone has seen scripting language
on the internet. My scripts look "amazing" to an unskilled person. A real programmer
would laugh at the crazy "Rube Goldberg" construction. I'm completely self-taught.
They get the job done, which is all that really matters.

The truth is, I really need a plugin applet. The scripting apps I use make it easy to
incorporate add-ons, plugins, etc. If I start messing around with specific command
lines, they will not be recognized and I'll waste hours trying to make them work.

message edited by Rich71

Reply ↓  Report •

September 21, 2016 at 00:13:01
✔ Best Answer
I don't know of any plugin that does this kind of thing.

You could also ask yourself the question "Why would a developer bother creating a plugin for this task, when it can be so simply achieved without any 'hardcore' code?". There is no point.

You could "make your own" using a slightly modified version of the code I provided.

@echo off
setlocal enabledelayedexpansion
if "%~1"=="" echo Syntax error. No process name provided. & exit /b
set PROGRAM=%~1
tasklist /FI "imagename eq !PROGRAM!" 2>nul | find /i /n "!PROGRAM!">nul
if %errorlevel%==0 (
        exit /b
goto :loop

Paste this in a batch file called, say "WaitForProgram".

You can now use WaitForProgram in any script of your choice, just like a plugin.

To use it, type somethnig like this in your main scrip, where PROGRAM.EXE is the program you want to wait for:

call WaitForProgram "PROGRAM.EXE"

This should halt the script until the process is running.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ

Reply ↓  Report •

Related Solutions

Ask Question