Julia Community 🟣

Vinod V
Vinod V

Posted on

Julia: Shutdown and Restart Your PC with Ease

using InteractiveUtils

println("1. Shutdown Computer Now")
println("2. Shutdown Computer after t seconds")
println("3. Restart Computer Now")
println("4. Restart Computer after t seconds")
println("5. Exit from program")
println("Enter Your Choice: ")
choice = parse(Int, readline())

if choice == 1
    run(`shutdown /s /t 0`)
elseif choice == 2
    println("Enter Number of Seconds: ")
    sec = parse(Int, readline())
    run(`shutdown /s /t $sec`)
elseif choice == 3
    run(`shutdown /r /t 0`)
elseif choice == 4
    println("Enter Number of Seconds: ")
    sec = parse(Int, readline())
    run(`shutdown /r /t $sec`)
elseif choice == 5
    exit()
else
    println("Wrong Choice!")
end
Enter fullscreen mode Exit fullscreen mode

In this code the line using InteractiveUtils is importing utilities to interact with the operating system.

Please note that executing commands to shutdown or restart a computer may require administrative privileges. Additionally, make sure you have the necessary permissions to execute such commands on your system.

Top comments (3)

Collapse
 
oheil profile image
oheil

InteractiveUtils seems to be not needed in this script. It works without using InteractiveUtils.

Collapse
 
ohanian profile image
Steven Siew

Does this works on Windows???

Collapse
 
vinodv profile image
Vinod V

Yes