windows的nohup后台运行

在Linux系统中,可以通过nohup命令运行python程序,实现后台运行。windows操作系统也可以实现类似功能。

1. 适用操作系统

本文主要使用win10,其他版本windows可以尝试,如果不行,请另行他法。假设test.py如下程序:
    import os
    source_path=r'D:\zjc\Daily_Batch\fastapitest\test_walk'
    print(f'进程id:{os.getpid()}')
    time.sleep(60)
    for root,dirs,files in os.walk(source_path):
        print('当前目录为:',root)
        print('当前目录下的子目录为:')
        for dirname in dirs:
            print(os.path.join(root,dirname))
        print('当前目录下的文件为:')
        for filename in files:
            print(os.path.join(root,filename))

2. pythonw方法

pythonw test.py
查看test.py相关进程信息
tasklist | findstr pythonw

3. powershell方法


Start-Process -WindowStyle hidden -FilePath python test.py

tasklist | findstr python
posted @ 2024-09-02 11:22  stone9693  阅读(1474)  评论(0)    收藏  举报
GitHub账户:https://github.com/stone9693