Reputation: 591
I wanted to make a batch script for killing a process with some process id. I scripted a few cmd commands as:
echo " So what is the process id that is blocking tcp.."
set /p prcs_id="Enter the process id of the process you want to terminate :"
pause
echo I got the process id: %prcs_id%
pause
taskkill /PID %prcs_id% /F
But the taskkill
code gives me the error as such :
ERROR: Invalid syntax. Value expected for /PID
What might be the possible cause for this- since when I run the command as it is in cmd I get no error...
Upvotes: 0
Views: 999
Reputation: 64672
I recommend adding a line in your file
set /P prcs_id="Enter a process id : "
echo I got process ID: %prcs_id%
taskkill /PID %prcs_id% /F
See if the prcs_id
is exactly what you think you entered.
I suspect that for some reason, it is not quite what you think you typed in?
I'm not entirely sure, but this may be the delayed-expansion problem. Near the top of your batch file, add:
setlocal enabledelayedexpansion
Then, change your taskkill line to be:
taskkill /PID !prcs_id! /F
(use !
instead of %
)
Upvotes: 1
Reputation: 809
Try this one.
@ECHO OFF
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit)
SET /P MyPID=Please enter your PID:
IF "%MyPID%"=="" GOTO Error
ECHO This %MyPID% PID will terminated
GOTO End
:Error
ECHO You did not enter PID
:End
pause
taskkill /PID %MyPID% /t
Upvotes: 0