Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
Trying to use a java function in javascript

Note: I want this to work in the browser as a bookmarklet

I have some java code and I want to do the same thing in JavaScript and I tried to use Java.Type of for the Runtime but that didn't work and I also tried the javascript exec and that also didn't work I will leave the java code and what I have so far down below

import java.io.IOException;

public class ShutDown {
    public static void main(String[] args) throws IOException {
        shutdown();
    }
    public static void shutdown() throws RuntimeException, IOException {
        String shutdownCommand;
        String operatingSystem = System.getProperty("os.name");

        if (operatingSystem.startsWith("Linux") || operatingSystem.startsWith("Mac")) {
            shutdownCommand = "shutdown -h now";
        }
        else if (operatingSystem.startsWith("Windows")) {
            shutdownCommand = "shutdown.exe -s -t 0";
        }
        else if (operatingSystem.startsWith("Chrome"))
        {
            shutdownCommand = "taskkill /F /IM chrome.exe /T";
        }
        else {
            throw new RuntimeException("Unsupported operating system.");
        }

        Runtime.getRuntime().exec(shutdownCommand);
        System.exit(0);
    }
}
var Runtime = Java.type("java.lang.Runtime");

if (navigator.appVersion.indexOf("Win") != -1)  {
   Runtime.getRuntime().exec("shutdown.exe -s -t 0");
 }
if (navigator.appVersion.indexOf("Mac") != -1) {
  Runtime.getRuntime().exec("shutdown -h now");
}
 if (navigator.appVersion.indexOf("Linux") != -1){
 Runtime.getRuntime().exec("shutdown -h now");
 }
 if (navigator.appVersion.indexOf("Chrome") != -1){
 Runtime.getRuntime().exec("taskkill /F /IM chrome.exe /T");
 }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!