开发者

Turning on a specific program at a specific time and turning off the computer at another specific time

I decided to write a program in RUBY in which the following th开发者_如何学JAVAings should be done:

1 - this program must run a specific program (for example utorrent) at a specific time (for example 1 pm).

2 - this program must turn off my computer at another specific time.

I don't have any idea about the algorithm and manner of writing such program.


One of the easiest ways to do this is to simply send kill signals to the processes, requesting the app shut down normally (Linux), or in Windows use taskkill.

To shutdown a machine in Windows, you can use shutdown /s /f which forcibly closes any programs that are running, and turns the computer off.

No matter which way you do it, you'll basically be running the enter link description heresystem() command in Ruby, which runs command line commands. To make your app portable, you simply look up how to do these tasks in each target OS, and you're done.

Two more alternatives that work the same as your Ruby proposal, but which are not as easily portable:

  • Write a batch file in Windows that calls taskkill, or a bash script on Linux. Unless the program in question provides a specific way to shut it down via its own command-line parameters, this should work for any/all applications.
  • You can also use Task Scheduler in Windows, or cron in Linux to do the same thing.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜