Windows 中终止子进程,访问被拒绝

发布于 2024-09-02 01:02:54 字数 373 浏览 7 评论 0原文

-

import time
import subprocess
from os.path import expanduser

chrome_path = expanduser('~\Local Settings\Application Data\Google\Chrome\Application\chrome.exe')

proc = subprocess.Popen(chrome_path)
time.sleep(4)
proc.terminate()

输出:WindowsError:[错误 5] 访问被拒绝

如何终止 Chrome 进程?

Windows XP 上的 Python 2.6。

-

import time
import subprocess
from os.path import expanduser

chrome_path = expanduser('~\Local Settings\Application Data\Google\Chrome\Application\chrome.exe')

proc = subprocess.Popen(chrome_path)
time.sleep(4)
proc.terminate()

Output: WindowsError: [Error 5] Access is denied

How can I kill the Chrome process?

Python 2.6 on Windows XP.

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

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

发布评论

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

评论(3

别忘他 2024-09-09 01:02:54

我不了解 Windows,但注意到在 Linux 上,Google Chrome 以很少有程序能做到的方式“保护”自身免受操作系统控制信号的影响:

$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome
$ kill -TERM 2345
$ kill -HUP 2345
$ kill -SEGV 2345
$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome

我怀疑这可能是您遇到麻烦的根本原因。顺便说一句,我发布了进程 2345 中的这条注释。

I don't know about Windows, but have noticed on Linux that Google Chrome "protects" itself from operating system control signals in a way that few programs do:

$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome
$ kill -TERM 2345
$ kill -HUP 2345
$ kill -SEGV 2345
$ ps -lp 2345
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1000  2345     1  0  80   0 - 17699 skb_re ?        00:00:00 chrome

I suspect this may be the root cause of your troubles. Incidentally, I'm posting this note from process 2345.

柏林苍穹下 2024-09-09 01:02:54

如果使用 TASKKILL /F /PID [进程 ID 号] 会发生什么?尝试一下。通过导入操作系统启动它

what happens if you use TASKKILL /F /PID [number of process ID] ? Give it a try. Launch it through import OS

近箐 2024-09-09 01:02:54

我认为最好的选择是在操作系统级别找到并关闭窗口: http:// python.net/crew/skippy/win32/Downloads.html

I think the best bet is to find and close the window at the os level: http://python.net/crew/skippy/win32/Downloads.html.

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