如何代表 Perl 中的进程完成 Win32 中的进程?

发布于 2024-09-24 10:50:58 字数 43 浏览 0 评论 0原文

例如,拥有 rschit 进程 Excell.exe 意味着 Perl。

For example, to have rschit process excell.exe means Perl.

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

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

发布评论

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

评论(2

耳钉梦 2024-10-01 10:50:58

如果这是关于自动化后仍处于“服务器模式”的进程,您只需调用应用程序对象上的 quit 方法即可。我通过 如何在使用 Perl 打开的 Excel 文件中运行宏? 以包含该宏。 (您知道,我想如果我告诉您这是一个 Application 对象,您可以阅读 该对象的 MS 文档 以确定您想要执行的操作。)


但是,您可以使用 taskkill 终止 Windows 中的进程。 exe.您可以通过在命令行中输入 taskkill /? 来阅读。它将处理taskkill /IM excel.exe

但如果您想要特定的PID,则需要使用tasklist.exe。 (在命令提示符处键入 tasklist 以查看输出。或者键入 tasklist /? 以获取更多信息。)

下面的代码同时使用了两者:

use strict;
use warnings;
use English qw<$OS_ERROR>;
use File::Spec;

my $sys32dir = File::Spec->catfile( $ENV{SYSTEMROOT}, 'System32' );
my $tasklist_exe = File::Spec->catfile( $sys32dir, 'tasklist.exe' );
my ( $excel_line ) = grep { /^excel.exe\b/i } `$tasklist_exe`;
# $excel_line: 'EXCEL.EXE  4468 Console  1  20,968 K

# The PID is the second column
my ( undef, $pid ) = split qr{\s+}, $excel_line;

if ( my $rc = system( File::Spec->catfile( $sys32dir, 'taskkill.exe' )
   , '/PID', $pid 
   )) {
    die ( $OS_ERROR + 0 ) . ' - ' . $OS_ERROR;
}

If this is about the process remaining around in "server mode" after automation, you can just call the quit method on the application object. I edited by answer at How can I run a macro in an Excel file I open with Perl? to include that. (You know, I thought if I told you that it was an Application object, you could read the MS documentation on that object to figure out what you wanted to do. )


However, you can kill a process in windows with taskkill.exe. You can read up by typing taskkill /? on the command line. It will handle taskkill /IM excel.exe.

But if you want a specific PID, you need to use tasklist.exe. (Type tasklist at the command prompt to see the output. Or tasklist /? for more information.)

The code below uses both:

use strict;
use warnings;
use English qw<$OS_ERROR>;
use File::Spec;

my $sys32dir = File::Spec->catfile( $ENV{SYSTEMROOT}, 'System32' );
my $tasklist_exe = File::Spec->catfile( $sys32dir, 'tasklist.exe' );
my ( $excel_line ) = grep { /^excel.exe\b/i } `$tasklist_exe`;
# $excel_line: 'EXCEL.EXE  4468 Console  1  20,968 K

# The PID is the second column
my ( undef, $pid ) = split qr{\s+}, $excel_line;

if ( my $rc = system( File::Spec->catfile( $sys32dir, 'taskkill.exe' )
   , '/PID', $pid 
   )) {
    die ( $OS_ERROR + 0 ) . ' - ' . $OS_ERROR;
}
我是有多爱你 2024-10-01 10:50:58

您是否尝试过向“taskkill /IM excel.exe”发出系统调用?

have you tried to fire a system call to "taskkill /IM excel.exe" ?

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