如何在 Win32 上终止 Perl 中可能不存在的程序? [英] How can I kill a program that might not exist from Perl on Win32?

查看:41
本文介绍了如何在 Win32 上终止 Perl 中可能不存在的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,让 Perl 杀死 Win32 上的所有 firefox.exe 进程,并且如果不存在任何进程,则不会出错.我目前正在使用:

I'm looking for a way to make Perl kill all firefox.exe processes on Win32, and not give an error if no process exists. I'm currently using:

system('taskkill /F /IM firefox.exe');

当 Firefox 不存在时,它会抛出一个很大的错误:找不到这样的进程".

which throws up a big "ERROR: No such process found", when firefox wasn't present.

推荐答案

如果你想抑制包括错误在内的所有输出,试试这个:

If you want to suppress all output including errors, try this:

system('taskkill /F /IM firefox.exe >nul 2>&1');

您可以在此处查看有关命令重定向和管道的更多信息:

You can see more information about command redirection and pipes here:

http://ss64.com/nt/syntax-redirection.html

这篇关于如何在 Win32 上终止 Perl 中可能不存在的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆