Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda