A
A
atomos902018-03-17 15:26:40
cmd/bat
atomos90, 2018-03-17 15:26:40

How to run a script under windows without being attached to it?

Script 1 runs on the scheduler and checks if script 2 is running and runs it if not. Script 2 runs in an infinite loop (daemon). It is necessary that script 1 starts script 2 and ends (closes itself), and does not wait for script 2 to close.
In CentOS, this was solved like this: "nohup SCRIPT_2 1>/dev/null 2>/dev/null &"
Is there a similar solution under windows? "start /min SCRIPT_2 >NUL" doesn't help. Script 1 window remains running and waits for script 2 to close

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2018-03-17
@atomos90

The solution under Windows is to run the script through the start command - it definitely works, I personally checked it 200 times and you don't need to convince me otherwise.
If it doesn’t work for you, then you need to figure out why, errors or what? If it's just waiting for closing, show the code of your script1, the part where start +- is a few lines.
And yes, I hope your script1/2 in real life have other names and are not called start.bat for example.

P
pantsarny, 2018-03-17
@pantsarny

Can you suggest going the other way? Use Mutex.
You only need one (main) script in this case, which starts like this (php):

<?php
$lock = @fopen('bot.lock', 'w');
if (false === $lock || false === @flock($lock, LOCK_EX | LOCK_NB)) {
    return;
}

The bottom line is that at startup the script creates a file and makes an exclusive lock on it. If the file is already locked, the script exits. In any case, when the process falls off, the lock on the file will also fall off, and accordingly the code will move on.

E
Ezhyg, 2018-03-17
@Ezhyg

Script 2 runs in an infinite loop (daemon

You can do even easier - make this "script" a service (i.e. a real "daemon") and then let the OS itself monitor its state, in particular, restart it in case of a crash.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question