issue running a batch script to kill a process
Posted
by
user657064
on Stack Overflow
See other posts from Stack Overflow
or by user657064
Published on 2011-03-13T00:06:32Z
Indexed on
2011/03/13
0:10 UTC
Read the original article
Hit count: 215
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:\Temp>kill $(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...)
© Stack Overflow or respective owner