Trouble running TASKKILL from GitBash - windows

I'm trying to create a function in my .bashrc to run in gitbash. The command I'm trying to run is:
cmd '/C TASKKILL /fi "WINDOWTITLE eq Windows Task Manager"'
I'll be changing the "Windows Task Manager" bit, but just to show what I'm trying. The command (TASKKILL /fi "WINDOWTITLE eq Windows Task Manager") works fine when I run it through Windows cmd, but when I run from gitbash, I get this error message:
ERROR: Invalid argument/option - 'eq'.
Type "TASKKILL /?" for usage.
As I said, it works fine in cmd, so I'm thinking it's something to do with the quotation marks. I've also tried the following, which also fails:
cmd "/C TASKKILL /fi \"WINDOWTITLE eq Windows Task Manager\""
I could put the command in a .bat file and run that (cmd "/C pathtofile/script.bat") and that works, but I'd prefer to run it straight from the .bashrc, if possible.

cmd "/C TASKKILL /fi "WINDOWTITLE eq Windows Task Manager""
It seems like it shouldn't work due to how the quotation marks are nested, but it does.

Related

TASKKILL specific Python script

I have a working TASKKILL command that kills python.exe using Process Name
I'd like to narrow the scope of the command to kill a specific process (myScript.py) but can't use ProcessID as it changes with every run.
Is there a way I can add detail from the Command Line which knows the python script's name?
Current Command:
Taskkill /IM python.exe /F >nul 2>&1
if errorlevel 1 (echo PYTHON.exe NOT FOUND) else (echo PYTHON.exe KILLED)
You might be able to kill it based on your Python script's memory usage. In my case, the Python script is running a GUI, so the size gives it away.
taskkill /f /fi "IMAGENAME eq python.exe" /fi "MEMUSAGE gt 130000"
This reads as, forcefully kill the task (taskkill /f) identified by (/fi) the Python executable (IMAGENAME eq python.exe) which is using more than 130,000KB (MEMUSAGE gt 130000)1.
1 See taskkill /? for builtin help.
N.B. You might find this SO post helpful: Find Windows PID of a python script with Windows Command Prompt. Unfortunately, for me, It Doesn't Work™ but maybe you will have better luck.

Task Manager CMD.EXE Description

I have a Windows batch script which issues the following command:
start "%IDT%_%IDTU%" D:\Apps\P_PROC\SNF2.BAT %IDF% %IDT% %IDTU% "%FNAME%" "%PARM%" "%NFNAME%" %PART% "%COMMENT%" %RPART%
When I go to Task Manager, the process CMD.EXE always shows a Description of "Windows Command Processor." If I have many start(s) triggering, how can I get the title from my start command as the Description in Task Manager?
Try using
tasklist /v /fi "imagename eq cmd.exe"
from the command prompt.
Or - use the applications tab rather than processes

Cannot kill a process using the window title

I have two batch file one is always running (listerner.bat) but it is visible,the other one (mystop.bat)is to kill or stop my listener.bat and this two batch file are resides in this path C:\mydemo\mybatchfiles\,I am using windows 7
here is the code for mystop.bat
taskkill /F /FI "WINDOWTITLE eq Administrator: testlistener" /T
but when I run it,it will not terminate the running (listener.bat),There is no error but I have this message when I run it.
INFO: No tasks running with the specified criteria.
I appreciate someone can help me on this.I am new on this batch file command.
I had the same problem. In my case it was that there were two spaces in the window title:
taskkill.exe /F /FI "WindowTitle eq Administrator: TailingErrorLog"
^^
Taskkill considers the command currently executed by listener.bat as part of the title. So you need to add a wildcard "*".
taskkill /F /FI "WINDOWTITLE eq Administrator: testlistener *" /T
Try terminating using Im switch ..
Taskkill /Im listener.bat /t /f
Although this is not computer science related question , thought I should help ...

how to kill all batch files except the one currently running

How can you run a batch file which taskkills all other cmd.exes which are currently running, except for the one that is doing the task kill command?
Combining these 2 threads:
how to get PID from command line filtered by username and imagename
how to get own process pid from the command prompt in windows
you can write down something like this in a simple cmd file (akillfile.cmd)
title=dontkillme
FOR /F "tokens=2 delims= " %%A IN ('TASKLIST /FI ^"WINDOWTITLE eq dontkillme^" /NH') DO SET tid=%%A
echo %tid%
taskkill /F /IM cmd.exe /FI ^"PID ne %tid%^"
copy cmd.exe, rename it to a.exe, then use this command in a batch file: start a.exe /k taskkill /f /im cmd.exe
This worked for me, added to the very beginning of the .bat which is to kill all previously launched instances of itself, then immediately make itself susceptible to be killed by subsequent calls of the same .bat file:
title NewlyLaunchedThing
taskkill /F /IM cmd.exe /FI "WINDOWTITLE ne NewlyLaunchedThing"
title Thing
...do everything else
Note that, apparently, the "title" is a keyword, which sets a variable named "WINDOWTITLE".
Also, the "=" (equals sign) is apparently optional for assigning title/WINDOWTITLE. Meaning, this works as well, and may be preferred for clarity:
title = newTitle

Batch script to close all open Command Prompt windows

I have a .cmd file which I call to open multiple instances of Command Prompt via:
launcher.cmd -fs
launcher.cmd -tds
launcher.cmd -fsd
Each command open a new command prompt.
So what I want to do is create a batch file to automatically close all the opened Command Prompt instead of manually doing it.
Be carefull: you might kill more processes than you want:
taskkill /IM cmd.exe
You can add extra filters:
taskkill /IM cmd.exe /FI "WINDOWTITLE eq launcher*"
use
tasklist /FI "imagename eq cmd.exe " /V
to get a glimpse of what cmd.exe processes will be taskkill-ed
You could add the /F parameter to force the process to close but I would only use that if the process doesn't respond to a normal request.
Just a little note why accepted answer from Rene may not work. I was starting my apps from cmd file like
start "" my.exe -my -args
where my.exe was a console app and it was looking like cmd window I wanted to kill, but process name was not cmd.exe (!) and I had to use command like
taskkill /IM my.exe
So in some cases it worth to check the real process name, for example in the windows task manager.
TASKKILL /F /IM cmd.exe /T
good solution

Resources