These forums are archived

See this post for further info

get_iplayer forums

Forum archived. Posting disabled.

Detecting when get_iplayer is executing across windows shells

user-250

When my windows workstation locks it disables the Ethernet and Wi-Fi adapters, when unlocked it enables them again. I am allowed to stop this happening if say a network backup is happening.

Is there a built in method I can interrogate to determine if get_iplayer is running?

What I've currently tried is below. I write running / not running to a file in GIPs home directory.

This is fine for a single instance of GIP, but multiple instances may cause problems.

Is there a better way?

e.g

get_iplayer Output:

@echo off
echo gip_running > %userprofile%\.get_iplayer\gip
setlocal
set GIP_INST=%~dp0
if #%GIP_INST:~-1%# == #\# set GIP_INST=%GIP_INST:~0,-1%
if "%GIP_PATH%" == "" set GIP_PATH=%GIP_INST%\perl;%GIP_INST%\utils;%PATH%
if not "%GIP_PATH%" == "" set PATH=%GIP_PATH%
perl.exe "%GIP_INST%\get_iplayer.pl" %*
echo gip_not_running > %userprofile%\.get_iplayer\gip

user-1949

First two disclaimers:
- This is not (necessarily) a better way, but it's a different way that may give you an idea.
- I'm not a windows shell expert - give me a 'nix shell any time...

Keep the "flag" file %userprofile%\.get_iplayer\gip, but keep a numerical value within; set initially to "0".
Every time you start GiP, increment this value, and every time it finishes, decrement it.
When it's zero, it should be a very good indicator that there are no GiP processes running.
I don't know what is starting your wrapper script, but the worst case is that they're asynchronous.  You should really implement some sort of lock on the "flag" file so that two instances don't try & modify it at the same time.

HTH

pf

user-2

If you are restricted to a single flag file, then @t_offlock explained the situation pretty well. If you can script a solution, some other options:

1. Give your flag files unique names with a common prefix. You can use %DATE% and %TIME%  (as long as you start get_iplayer sessions at least .01 sec apart),  or possibly %RANDOM% for uniqueness - google for different methods. Delete the flag files when get_iplayer finishes rather than overwriting them. The presence of any files with the magic prefix (if exist \path\to\files\prefix* (...) in batch parlance) would be the signal that get_iplayer is running. No need to worry about file locking in that case.

2. Check the list of running processes for perl. If you don't otherwise use perl, it will only be running when get_iplayer is running. You can use the SysInternals PsList utility available from Microsoft. From a batch file, run pslist perl then check %ERRORLEVEL%. It will be 0 if any perl processes are running, 1 if not.

user-250

Thanks both, food for thought. I'm more used to *nix.
I thought of incrementing a variable about 5 seconds after I pressed enter.
.
Googling, I found out that I can use the built-in tasklist to determine if a file is running
tasklist | find /I "perl.exe"
perl.exe 10332 Console 1 54,648 K

These forums are archived

See this post for further info