0

Whenever i try to kill the ngrok.exe task (start /B "ngrok" call ngrok.exe tcp 22 -log=stdout > ngrok.log) with taskkill (taskkill /IM ngrok.exe /F) it doesn't work. Apparently i kill the ngrok.exe process but Windows Command Prompt (session handler) is still there.

When I try to run the exe again it says: The process cannot access the file because it is being used by another process.


I've also tried to add /T to taskkill and get rid of any child processes, but it doesn't work too. Any solutions?


Before any actions

After launching ngrok

After taskkill

dheb
  • 1
  • 2
  • I know this isn't your question but I myself don't understand your use of `call`.. this is for running batch processes from within other batch processes (either by label or file). Have you tried ditching the start /b to see if it works when not running within the same terminal? – Señor CMasMas Oct 29 '21 at 23:41
  • Also, for your edification.. how I myself would figure this out would be to use a better task manager (like sysinternals process explorer) and SEE what is going on.. sometimes a picture is worth a thousand words. = – Señor CMasMas Oct 29 '21 at 23:44
  • @SeñorCMasMas Thanks for help, I deleted call command and everything works fine now :) – dheb Oct 30 '21 at 09:05
  • AWESOME @dheb :) Glad it works now!! – Señor CMasMas Oct 30 '21 at 22:57
  • @SeñorCMasMas, since you effectively fixed the issue, why not make that an answer? – DrMoishe Pippik Oct 31 '21 at 02:33

1 Answers1

0

The problem that I see is your use of the call command within your start command.

call is only used within a batch process to invoke functionality from within other batch processes (either by label or file).

ex:
call :MyLabel <- where MyLabel is a label defined in the same file.
or
call "c:\mypath\dumb.bat" <- after this batch runs, it will continue from here

In this case, this is not what you wan't as these are the only uses for call.

A quick lesson about the call command

Also, even though this wasn't what you wanted.. since we are on the subject of when to use call.. Why not simply use goto or directly invoke a batch file?

The reason for the label method is that call can be used like a function by calling a batch label. After the label is called, the code after the label (sort of like a function) can return to where the call statement was invoked by either using goto :EOF or exit /b creating a very "function like" behavior within batch. In the before times, this was like GoSub and Return used in basic.

If you don't use call when invoking a batch file from another batch file, the process will simply exit after invoking the second batch file (leaving one bewildered as to why the batch stopped).

OTHERWISE, DON'T USE IT! :)

Señor CMasMas
  • 4,794
  • 1
  • 11
  • 27