C # timed Python script execution

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Diagnostics;usingsystem.timers;namespacecmdpython{classProgram {Static voidMain (string[] args) {Timer Timer=NewTimer (60000); //timer. Interval = 60000;//execution interval time: 60 seconds, in milliseconds, one minute to judgetimer. Enabled=true; Timer. Elapsed+=NewElapsedeventhandler (timer1_elapsed); Timer. AutoReset=true; Timer.            Start (); Console.WriteLine ("the Python drawing program starts with a daily average value of 9:20; hour: 6:30. Execution");        Console.ReadLine (); }        Private Static voidTimer1_elapsed (Objectsender, System.Timers.ElapsedEventArgs e) {            //get hour minute second start executing a program if it equals a value.             intInthour =E.signaltime.hour; intIntminute =E.signaltime.minute; if(Inthour = =9&& Intminute = = -) {Console.WriteLine ("start to perform daily average value drawing,"+e.signaltime.date); Dopython ("python","e:/python/drawyesteday_day.py"); }            if(Inthour = =6&& Intminute = = -) {Console.WriteLine ("start the execution of the time-out drawing,"+e.signaltime.date); Dopython ("python","e:/python/drawyesteday_hour.py"); }        }        Private Static voidDopython (stringStartFileName,stringStartfilearg) {Process cmdprocess=NewProcess (); CmdProcess.StartInfo.FileName= StartFileName;//CommandCmdProcess.StartInfo.Arguments = Startfilearg;//ParametersCmdProcess.StartInfo.CreateNoWindow=true;//do not create a new windowCmdProcess.StartInfo.UseShellExecute =false; CmdProcess.StartInfo.RedirectStandardInput=true;//REDIRECT inputCmdProcess.StartInfo.RedirectStandardOutput =true;//REDIRECT standard outputCmdProcess.StartInfo.RedirectStandardError =true;//REDIRECT error output//CmdProcess.StartInfo.WindowStyle = Processwindowstyle.hidden; Cmdprocess.start ();            Cmdprocess.beginoutputreadline ();            Cmdprocess.beginerrorreadline (); //If you open a comment, the command executes synchronously, and this example executes asynchronously with the exited event. Cmdprocess.waitforexit ();        Cmdprocess.close (); }    }}

C # timed Python script execution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.