类似nohup在windows通过cmd后台运行进程方法

发布时间 2023-07-16 15:32:11作者: 老铁来了啊

Linux后台运行进程时,通常使用如下方法:

nohup "运行的内容" &

windows相应功能的命令行如下(此方法进程有页面,可能会在桌面展示,关闭窗口后进程消失。

call start /min "n" "运行的内容"

cmd下难以实现nohup能力,但使用powershell可以。
以下powershell方法,可实现后台运行,退出powershell后依然运行。

Start-Process -WindowStyle hidden -FilePath "运行的内容" 

实用,另外写在bat里面的方法,可打开任务管理器,详细信息里找到自己运行的程序:

pushd %~dp0
powershell.exe -command ^
"& {Start-Process -WindowStyle hidden -FilePath '程序文件路劲'}"
popd
pause

如何停止:
查看当前进程

tasklist |findstr "进程名"

还可以通过进程id查看端口号:

netstat -ano|findstr "13192"

杀死进程:

kill 进程id