简体   繁体   中英

Why can't I run an application or console from within Java?

I am trying to update a 200,000 line program written in Java/Eclipse in 2009.

I imported it to the latest Eclipse/Java, and there are several problems:

  1. the following line (which ran inn 2009) generates an error message

     try { consoleProcess = Runtime.getRuntime().exec("/Applications/Utilities/Console.app/Contents/MacOS/Console"); } catch (Exception err) { err.printStackTrace(); }

The error message is "java.io.IOException: Cannot run program "/Applications/Utilities/Console.app/Contents/MacOS/Console": error=2, No such file or directory at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1142)"

However, the file is definitely there, it shows up in the finder (although not in an "ls" command from a terminal window, which I'd also like to get input on.) and I can click on it and run it. I also cannot run BBEdit this way: I can however run open/run XQuartz using similar code.

I started trying to write around this problem by trying to open a console with the following code, which however produces the error message that "The console is NULL"

import java.io.Console;



    Console console = System.console();
    if(console == null) {
        System.out.println("The console is NULL");
    }        
    else 
    {
        String  ch=console.readLine();    
    }

Thanks so much !!

Use the macOS open command to run an application:

open -a Console

You can't find Console using the ls command in /Applications because Finder is actually showing the contents of /Applications merged with /System/Applications . The path to Console is actually:

/System/Applications/Utilities/Console.app/Contents/MacOS/Console

This split was introduced in macOS Catalina.

Note: System.console() is something else entirely, it isn't available in Eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM