issue running a batch script to kill a process
- by user657064
I am using the following script on a command line to kill a hypothetical notepad process (using a Korn shell in Windows XP, if that matters):
kill $(tasklist | grep -i notepad.exe | awk '{print 2}')
Now I take this line, and put it into a batch file c:\temp\testkill.bat, thinking that I should just as well be able to kill the process by running the batch file. However, when I run the batch file, I get the following awk error about unbalanced parentheses:
C:/Temp ./testkill.bat
C:\Tempkill $(tasklist | grep -i notepad.exe | awk '{print $2}')
awk: unbalanced () Context is:
{print $2}) <<<
C:/Temp
So I'm baffled as to why I am getting this error about unbalanced parentheses when I run this script via a batch file, but have no issues when I run the command directly from the command line?
(Btw, I'm not necessarily tied to this way of killing a process - as a total noob to shell scripting, I am additionally wondering why if I write the following on the command line:
tasklist | grep -i notepad.exe | awk '{print $2}' | kill
the process ID that comes out of the tasklist/grep/awk calls doesn't seem to properly get piped to kill...)