Sublime Forum

How do I automatically run a compiled Java program in external terminal?

#1

I have a simple working java build system:

{
"shell_cmd": "javac $file_name && java $file_base_name",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
}

The program successfully compiles and all print statements show up inside Sublime Text’s own terminal.

However, I would like to have an external terminal (cmd prompt or powershell) open up automatically and run the program via the java “Program Name” command. Is there anyway I can make the build system call an external terminal (in the same location as the file being compiled) and pass the java “filename” command to that terminal and run?

0 Likes

#2

Indeed there is; you need to specify a command that will cause the appropriate terminal to open up and pass it the required command. How you do that is different depending on the operating system you’re on.

These videos cover how you would do this for any of the operating systems that Sublime runs on; you just need to replace the sample commands used in the video for demonstration purposes with your command from the build you’ve already got and you should be good to go.

1 Like

#3

Thanks so much man!

You’re always so quick to reply too, I really appreciate it.

0 Likes

#4

EDIT: I watched your video and the solution works perfectly with cmd. However, I can’t seem to get powershell to work. Powershell opens and closes immediately even when using /k

0 Likes

#5

I suspect PowerShell takes a different argument to get it to hang around. I’ve only used it sporadically through the years though so I’m not sure offhand if there’s an argument for it that lines up with what cmd uses.

1 Like