通过管道传输到 find 的过滤任务列表不显示控制台输出?

发布于 2024-08-19 01:05:39 字数 350 浏览 11 评论 0原文

Windows XP Pro

这在控制台中显示输出:

dir | find " free"

这不:

tasklist | find "Image Name"

确实

tasklist | find /C "Image Name"

确实将预期的行写入文件:

tasklist | find "Image Name" > foo.txt

是什么原因导致的?

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 file:

tasklist | find "Image Name" > foo.txt

What causes that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

靑春怀旧 2024-08-26 01:05:39
> tasklist | find "Image Name"
Image Name                     PID Session Name        Session#    Mem Usage

这里无法重现。您的第二个命令行确实按预期工作,这样当第四个命令行将该行写入文件时就不会出现混乱。

当您搜索 " free" 时,字符串中是否仍然有前导空格可以从上一行开始搜索?

> 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"?

迷你仙 2024-08-26 01:05:39

findstr 怎么样?你尝试过吗?

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

what about findstr? have you tried?

C:\test>tasklist  | findstr "Image Name"
Image Name                   PID Session Name     Session#    Mem Usage
﹎☆浅夏丿初晴 2024-08-26 01:05:39

如果 /C 标志显示找到了特定行,则“find”返回的字符串可能以某种方式被剥离(或作为字符串中的特殊字符)并且仅显示字符串的末尾?如果调整命令行窗口的大小会发生什么?

这是一个修复:

任务列表 |找到“3184”|排序

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

只涨不跌 2024-08-26 01:05:39

感谢 Stack Overflow,我有一段时间了解到这个问题的答案后退。 (显然我应该在这里发表评论而不是回答,但我还没有代表。)阅读链接,但摘要是tasklist.exe的输出有一些非打印垃圾,可以通过重定向标准错误来修复到 NUL: tasklist.exe 2>NUL |找到“图片名称”

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文