Python利用多线程定时执行cmd命令关机

利用os模块可以执行cmd命令,利用这一点可以实现定时关机,然而在等待关机的过程中也不能啥都不干,于是多线程派上了用场。

#! /usr/bin/env python
#coding=utf-8
#这里需要引入三个模块
import time, os, sched, easygui, thread

# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep) 

def perform_command(cmd, inc):
    os.system(cmd)
def reminder(cmd, inc = 60):
    # enter用来安排某事件的发生时间,从现在起第n秒开始启动
    schedule.enter(inc, 0, perform_command, (cmd, inc))
    # 持续运行,直到计划时间队列变成空为止
    schedule.run()
    thread.exit_thread()
if __name__=='__main__':
    print("show time after 10 seconds:")
    thread.start_new_thread(reminder, ("shutdown -s", 10))
    print'在这个等待过程中并不耽误我们干一些其他事情'
时间: 2024-08-25 12:19:15

Python利用多线程定时执行cmd命令关机的相关文章

C#执行cmd命令实现电脑关机

C#实现执行CMD命令,实现电脑立即/定时关机 该篇博文主要介绍个人写的一款实现立即与定时关机的软件: 主要是通过调用window下的cmd.exe,然后执行关机相关的cmd命令,实现电脑的立即和定时关机,具体实现如下. 首先是打开系统自带的cmd.exe: <span style="white-space:pre"> </span> Process process = new Process(); process.StartInfo.FileName = &q

java执行cmd命令

从网上找的java执行cmd命令的文章,摘抄一段. java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后封闭命令窗口. cmd /k dir 是执行完dir命令后不封闭命令窗口. cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会封闭. cmd /k start dir 会打开一个新窗口后执行dir指令,原窗口不会封闭. 可以用cmd / 查看帮助信息. ★CMD命令★1

执行cmd命令

说明:主要代码是从 http://tieba.baidu.com/p/3214053453 抄录的 Demo下载:https://git.oschina.net/xieyimo9/zhixingcmdmingling.git 主要思路: { 建立两条管道,一条负责从程序(进程)往新建立的cmd进程传信息,另一条则反过来,从cmd进程传信息给程序 程序通过 WriteIn 写入,cmd进程 从 ReadIn 读到程序写入的信息 cmd进程 的返回值或错误通过 WriteOut 写入,程序从 Rea

java 执行 cmd 命令(转)

原文出处:http://blog.csdn.net/saindy5828/article/details/11975527 用JAVA代码实现执行CMD命令的方法 java的Runtime.getRuntime().exec(arstringCommand)可以调用执行cmd指令. public class Cmd{ public void execCommand(String[] arstringCommand) { for (int i = 0; i < arstringCommand.le

Atitit.执行cmd 命令行 php

Atitit.执行cmd 命令行 php 1. 执行cmd 命令行,调用系统命令的基础 1 1.1. 实际执行模式 1 1.2. 空格的问题 1 1.3. 中文路径的问题,程序文件读取编码设置 1 1.4. 回显乱码 2 2. exec,system等函数调用系统命令 2 3. php.ini,关掉安全模式safe_mode = off 3 4. 参考 3 1. 执行cmd 命令行,调用系统命令的基础 1.1. 实际执行模式 Processmonitor 检查.得到.. PID: 115372,

JAVA之执行cmd命令

感言在前:时隔好久没有更新博客园了,忙东忙西也没忙出个什么之所以然来.回首过去的几个月,只能用“疲倦”两个字来形容,时间飞逝地很快,有苦也有乐,有酸也有甜. 好了,矫情的话就说到这.百忙之中,我还是记得抽些时间来更博. class ExecCmd { public static void main(String args[]) { Runtime run = Runtime.getRuntime(); Process process = null; try { process = run.exe

java执行cmd命令并获取输出结果

1.java执行cmd命令并获取输出结果 1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 4 import org.apache.commons.lang3.text.StrBuilder; 5 6 /** 7 * 8 * @author user1 9 */ 10 public class DeleteProgram { 11 public static void run() { 12 Runtime

.Net执行cmd命令

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.W

C# 执行CMD命令的方法

/// <summary> /// 执行CMD命令 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string ExeCmd(string str) { try { //string str = Console.ReadLine(); System.Diagnostics.Process p =