简体   繁体   English

如何在后台运行python脚本?

[英]How to run a python script in the background?

I have a script that checks something on my PC every 5 minutes and I don't want Python to show on my task tray.我有一个脚本每 5 分钟检查一次我的 PC 上的某些内容,我不希望 Python 显示在我的任务托盘上。 I use Windows as my operating system.我使用 Windows 作为我的操作系统。

Is there any way to make Python run in the background and force it to not show in my task tray?有没有办法让 Python 在后台运行并强制它不在我的任务托盘中显示?

If you run a console script using pythonw.exe , it will neither display a window nor appear in the task bar.如果您使用pythonw.exe运行控制台脚本,它既不会显示窗口,也不会出现在任务栏中。 For example, I use the following command to launch ntlmaps on startup:例如,我使用以下命令在启动时启动ntlmaps

C:\BenBlank\Python2.6\pythonw.exe scripts/ntlmaps

Be aware, however, that there is no way to interact with the script, nor to terminate it save via the Task Manager.但是请注意,无法与脚本交互,也无法通过任务管理器终止它保存。

Just another option you have:你还有另一个选择:

You can create a shortcut to your Python script, then right-click the shortcut --> Properties --> Shortcut tab您可以创建 Python 脚本的快捷方式,然后right-click the shortcut --> Properties --> Shortcut tab

There is a drop-down box under the Run option which lets you run the command minimized. “运行”选项下有一个下拉框,可让您运行最小化的命令。

You could run it as a service.您可以将其作为服务运行。 See here这里

cron it on linux;在 linux 上运行它; schedule it on windows [control panel > scheduled tasks > Add scheduled task]在 Windows 上安排它 [控制面板 > 计划任务 > 添加计划任务]

To Run python file from any where :从任何地方运行 python 文件:

Step 1:第1步:

Create Shortcut of Python File.

Step 2:第2步:

Place Shortcut in this location  C:\ProgramData\Microsoft\Windows\Start Menu\Programs

Step 3:第 3 步:

Now Right Click --> Go to Properties --> Shortcut --> Press any key on keyboard it will take one shortcut key

Step 4:第四步:

Now , Type the Shortcut key which you entered in previous step.

Step 5:第 5 步:

Check out Output!   :)

在控制面板中查找计划任务。

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

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