开发者

Filtered tasklist piped into find doesn't show console output?

Windows XP Pro

This shows output in the console:

dir | find " free"

This doesn't:

tasklist | find "Image Name"

This does:

tasklist | find /C "Image Name"

And this does write the expected line into the开发者_Go百科 file:

tasklist | find "Image Name" > foo.txt

What causes that?


> tasklist | find "Image Name"
Image Name                     PID Session Name        Session#    Mem Usage

Can't reproduce here. Your second command line does work as expected and that way no confusion arises when the fourth one writes that line into a file.

Did you perhaps still have the leading space in the string to search from the previous line when you searched for " free"?


what about findstr? have you tried?

C:\test>tasklist  | findstr "Image Name"
Image Name                   PID Session Name     Session#    Mem Usage


if /C flag showed that a particular line was found, maybe the string returned by 'find' was somehow stripped (or there as a special character in the string) and only the end of the string was displayed? What would happen if you'd resize the command line window?
Here is a fix:
tasklist | find "3184" | sort


Thanks to Stack Overflow, I learned the answer to this question a while back. (Apparently I should probably comment instead of answer here, but I don't have the rep yet.) Read the link, but the summary is that the output of tasklist.exe has some non-printing garbage that is fixed by redirecting standard error to NUL: tasklist.exe 2>NUL | find "Image Name"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜