Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tasklist and PID

12 views
Skip to first unread message

novice

unread,
Jul 29, 2017, 7:09:56 AM7/29/17
to
Hello

I need help, I don't know, how to do this.

I have a batch what running long time and I don't want to watch when it stop
and I want to run another batch after that first batch stop, I think to make
another batch, what use tasklist command.

(I know, I can start two batch like this first.cmd & second.cmd, but this
situation are when first is already running and you want to run second batch
after first and you don't want to cancel first batch).

Command example; Tasklist /NH /FI "pid eq 4952" found that specific batch,
what is running. It's use robocopy, so I cant use imagename with tasklist,
because next batch will use robocopy too. I want to create batch, what check
if this specific PID running. If it's running, nothing happend. If this PID
is not found anymore, I want to start second batch.

Example;
@Echo off
:start
timeout /t 600
tasklist /NH /FI "pid eq 4952"
"something if or loop trick here or little bit earlier, what check is that
PID running"
if running => goto start
call second_batch.cmd (if specific PID is not running, that call will be
executed)
:end


novice

unread,
Jul 29, 2017, 2:49:12 PM7/29/17
to
I found a solution. This batch work;

@echo off
setlocal enableextensions
:start
timeout /t 600
tasklist | find/i "4952" >nul
if %errorlevel% EQU 0 goto found
echo Not running
goto notfound
:found
echo Running
goto start
:notfound
echo call c:\bat\second.cmd
:eof


"novice" <nov...@invalid.fi.inv> wrote in message
news:62_eB.740$mh1...@uutiset.elisa.fi...

Herbert Kleebauer

unread,
Jul 29, 2017, 3:43:54 PM7/29/17
to
On 29.07.2017 20:49, novice wrote:

>> (I know, I can start two batch like this first.cmd & second.cmd, but this
>> situation are when first is already running and you want to run second
>> batch after first and you don't want to cancel first batch).

> I found a solution. This batch work;

> :notfound
> echo call c:\bat\second.cmd
> :eof


Why not just insert a line at the end of the first batch:

if exist token.txt del token.txt & call c:\bat\second.cmd

If you want to run the second batch file, just create the
file token.txt while the first batch is running.

Zaidy036

unread,
Jul 29, 2017, 5:28:43 PM7/29/17
to
*** All in one batch:
for the first RoboCopy use START "" /WAIT RoboCopy ....
for the second RoboCopy use START "" RoboCopy ...

- or -

*** Using two batches:
in the first batch use START "" /WAIT RoboCopy ....
then for the second batch use START "" [path to second batch]

0 new messages