zoukankan      html  css  js  c++  java
  • c# 定时执行python脚本

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Diagnostics;
    using System.Timers;
    
    namespace cmdPython
    {
        class Program
        {
            static void Main(string[] args)
            {
                Timer timer = new Timer(60000);
                //timer.Interval = 60000;//执行间隔时间:60秒,单位为毫秒,一分钟执行一次判断
    
                timer.Enabled = true;
                timer.Elapsed += new ElapsedEventHandler(Timer1_Elapsed);
    
                timer.AutoReset = true;
                timer.Start();
    
                Console.WriteLine("python绘制程序开始,日均值:9点20分;小时值:6点30分.执行");
                Console.ReadLine();
            }
    
            private static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                // 得到 hour minute second  如果等于某个值就开始执行某个程序。
                int intHour = e.SignalTime.Hour;
                int intMinute = e.SignalTime.Minute;
    
                if (intHour == 9 && intMinute == 20)
                {
                    Console.WriteLine("开始执行日均值绘制," + e.SignalTime.Date);
                    doPython("python", "E:/python/drawyesteday_day.py");
                }
    
                if (intHour == 6 && intMinute == 30)
                {
                    Console.WriteLine("开始执行小时值绘制," + e.SignalTime.Date);
                    doPython("python", "E:/python/drawyesteday_hour.py");
                }
            }
    
            private static void doPython(string StartFileName, string StartFileArg)
            {
                Process CmdProcess = new Process();
                CmdProcess.StartInfo.FileName = StartFileName;      // 命令  
                CmdProcess.StartInfo.Arguments = StartFileArg;      // 参数  
    
                CmdProcess.StartInfo.CreateNoWindow = true;         // 不创建新窗口  
                CmdProcess.StartInfo.UseShellExecute = false;
                CmdProcess.StartInfo.RedirectStandardInput = true;  // 重定向输入  
                CmdProcess.StartInfo.RedirectStandardOutput = true; // 重定向标准输出  
                CmdProcess.StartInfo.RedirectStandardError = true;  // 重定向错误输出  
                //CmdProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  
    
    
    
                CmdProcess.Start();
                CmdProcess.BeginOutputReadLine();
                CmdProcess.BeginErrorReadLine();
    
                // 如果打开注释,则以同步方式执行命令,此例子中用Exited事件异步执行。  
                CmdProcess.WaitForExit();
                CmdProcess.Close();
            }
        }
    }
  • 相关阅读:
    javascript中数据类型转换那些事
    CSS布局奇淫技巧之高度自适应
    用innerHTML插入html代码中有样式表时需注意的地方
    详解ASP.NET Core API 的Get和Post请求使用方式
    Speex 一个开源的声学回声消除器(Acoustic Echo Cancellation)(转)
    c# int byte转换
    Linux操作系统内核源码目录结构详解
    Linux/Ubuntu sudo不用输入密码的方法
    DirectX简介
    在VC工程中添加多语言支持
  • 原文地址:https://www.cnblogs.com/tiandi/p/5860423.html
Copyright © 2011-2022 走看看