简体   繁体   English

关闭在 web 浏览器上运行的脚本后如何关闭命令行 window?

[英]How to close command line window after closing script running on web browser?

I am running a dash application through cmd and after closing the web browser (https//127.0.0.1/8050) on which the dash application is running, I want to close the command line window from where the program was initially run.我正在通过 cmd 运行一个破折号应用程序,在关闭 web 浏览器(https//127.0.0.1/8050)后,我想关闭命令行 Z05B8C35CBD96FFBF2DE4ZC 最初运行的命令行。 Any idea how to do that?知道怎么做吗?

You will need to write a small javascript function for this.为此,您需要编写一个小的 javascript function。 So first when the application is started from your command line, get process id of the process that gets started, and pass this to a variable in dash.因此,首先从命令行启动应用程序时,获取启动进程的process id ,并将其传递给 dash 中的变量。 There are many ways of retrieving this process id.有许多方法可以检索此进程 ID。

Then an event listerner in javascript like so:然后是 javascript 中的事件监听器,如下所示:

window.addEventListener('beforeunload', function (e) {
    e.preventDefault();
    e.returnValue = '';
});

Finally in add a kill event using the process id you have collected at the start最后,使用您在开始时收集的进程 ID 添加一个终止事件

GetObject("winmgmts:").Get("Win32_Process.Handle='" + pid + "'").Terminate();

Here is the documentation for adding extra js to the dash application.这是向 dash 应用程序添加额外 js 的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM