Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda