python - 在 Mac(终端)/Windows(命令行)中自动执行 Python 脚本
问题描述
我希望 Python 程序使用终端,使用 mac 系统按计划或定期间隔执行,但 Windows 也可以接受解决方案。
以下是我想要实现的步骤。
step 1) Open terminal and enter : sudo start --init**
it will prompt to enter user name: usr_name
password '-------------'
step 2) after that run this command
function params1 --params2 “value”
step 3) After 3 to 4 minutes run the same program
, It will ask for killing the previous session and will ask to enter users master password.
or if we can do it in the same terminal press control+C
, it will end the current session and bring the terminal to next line
, then again the command function params1 --params2 “value”
,If we are doing this there will be no need to enter the user name and password as in step 1
以下脚本不起作用。在命令行中运行良好,但需要自动化和调度。调度是问题所在。
请提供任何帮助或建议。
import sys
import subprocess
import os
import openpyn
#sys.path.insert(1, ‘/Users/klr/Downloads/nordvpnipchange/openpyn/openpyn.py’)
#subprocess.check_output([‘ls’,‘-l’])
#subprocess.check_output([‘sudo openpyn --init’])
os.system(“sudo openpyn --init”)
#print(os.system(“sudo openpyn --init”))
#print (subprocess.check_output([“sudo openpyn --init”]))
第二个,
import subprocess
import os
subprocess.call(["openpyn DE --area “Berlin"], shell=True)
os.system("openpyn DE --area “Berlin")
用Mac中的Automator试了一下,如下图,但是不知道怎么安排。
解决方案
尝试使用Cron作业。这是有关如何开始的指南。
Cron 作业在调度脚本的运行和自动化方面非常受欢迎。
推荐阅读
- php - 使用 composer 安装 phpoffice/phpspreadsheet 时出错
- bash - 如何从列表中排除文件
- java - 使用 docker 设置带有公钥/私钥信息的 ftp .ssh 目录
- ios - 如何从显示时间的文本字段中减去分钟
- karate - 空手道:带有参数和循环的 AfterScenario
- python - Keras,可以处理输入的数据适配器:
, ” 在批量训练中 - python - 我们可以在 django 中加入多个基于通用类的视图吗?
- python - Python thread.join(超时)没有超时
- testing - Jest in Chai 中的“test.each”是否有等效功能?
- r - databricks/R ---- 错误:达到批次分辨率的最大迭代次数 (100)