I am a big fan of VSCode for how customizeable it is, but one thing really bugs me. I write code in Java, and for whatever reason scanners don't work with VSCode's default terminal, the internal console. It isn't a big deal, and I can fix it by just going into launch.json and changing the "console" option from internal console to integrated terminal, but it is annoying to do because one, I have to do it every time, and two, I have to run my Java file and watch it crash before the launch.json file even shows up.
TLDR: Is there some way to change the default so that it ALWAYS launches .java files in the integrated terminal instead of the internal console? I have looked around the settings multiple times and haven't found anything promising.
To be clear, I am not trying to change my default shell. I don't want to go from the standard prompt to powershell or bash or anything like that. I want to change the way it launches my programs.
Related
I have been writing java program that I start from the terminal. One of the tasks my program must perform is to open a text file in my favorite text editor. I have accomplished this fairly easily with the following command, but it only works in certain scenarios.
Runtime.getRuntime().exec("emacs "+p.fullName);
This works great when I am on my local Linux, and when I ssh in to a computer using the -X flag (for X11). At these times, the editor pops up in a separate window. However, if I ssh without -X, my beloved text editor never appears. It is the times that I am trying to open the editor in the same terminal as the Java program.
The reason for this seems to make sense, the java program is currently occupying the terminal, so the editor either gets created in a detached state or not at all. Either way, what I'd like to do is somehow put my program in the background and set up my editor as my foreground process. And is there a better term for this than context switching?
Edit: Emacs gives me this error at the moment: emacs: standard input is not a tty
Edit: Removed mentions of Lanterna, because bug is reproducible without it.
I executed a Java program from the command line in terminal app A. I want to move the console to terminal app B without having to exit and re-execute the program.
I can think of a few potential ways to solve this, ranging from:
A) In Java implement a new InputStream and OutputStream that somehow can be wired to a new process started in terminal app B.
...to
B) Find a way to put the main Java process in terminal app A in the "background" so that original process can be reopened in a terminal app B.
Ideally, I want to be able to "log in to" and "log out of" my Java process from any terminal on my computer. Has anything like this already been accomplished, and which approach would be best to make it myself? I am open to solutions that involve Java code, shell scripts, or both.
My specs:
OSX: 10.12.4
Usually running zsh on iTerm
If I was using Linux, the perfect solution would be reptyr, a command line tool that allows you to easily switch terminal windows.
On Mac, the best solution I have found is screen. It can also be used to switch terminal windows but must be invoked before running java in order to work and seems a lot more complex.
I am trying to access the command window contents using the code :
cmdWinDoc = com.mathworks.mde.cmdwin.CmdWinDocument.getInstance;
This works perfectly in MATLAB environment but when I deploy the app as a standalone application through the compiler my GUI shows no contents of the command window.
What files or lines needs to be included so that I can get the command window handle or its property active even in standalone apps ?
Thanks in advance !!
The question, and what you're trying to achieve, don't really make sense.
There is no command window in deployed applications, so attempting to retrieve a handle to it is not going to work.
You mention in a comment that you're trying to do this in order to get the messages generated by the deployed application. By default, when you deploy an application, messages that would have been delivered to the command window are instead displayed at the location from which you launched the application - for example, if you call it from a DOS or UNIX command line, they will display there.
If you're doing something like creating a Windows GUI, and there's nowhere for the messages to display, they will get swallowed up by Windows. In this case the appropriate thing for you to do is to modify your code, replacing the display commands (such as disp, fprintf etc) with commands that display the output within your GUI.
If you need to have behaviour that varies between in-MATLAB and deployed versions, place that code within an if block, using if isdeployed ... else ... end.
I am using IntelliJ IDEA version 11. And debugging my application using console.
Is it possible to use previous commands like in Linux shell with up arrow?
Also it would be great if I can prepare a list of commands and then select them in a smart way.
I am afraid that this is not possible.
For accepting user input(e.g. System.in), one can use either the built in console or one can even add an external command line tool as described here in the documentation. In Windows, I was able to successfully add the standard DOS prompt command line program to IntelliJ and use that to issue any commands that would be accepted by the OS, but even in that case, you do not have command history or autocomplete as discussed here
In the Editor setting, I see a setting "Console commands history size", but setting this doesn't seem to have any effect.
I may be missing something, but what console are you talking about? Debug console is output only, and command line console (which is not bundled with IDEA anyway) does have the arrow feature you asked.
I made a simple command-line based game in java, only two classes (using Eclipse). But I was wondering how I can make this into a usable application for anyone, without running it through eclipse (ie send it to someone who knows nothing about java but would still be able to play the game)? Thanks!
You want to create a runnable jar file.
Eclipse has an option for this in the "Export" menu. For more options, search for "executable jar file" here or on Google.
You want to make sure that you also include any jar files your code depends on as well (Eclipse can also do that for you).
Users will be able to start this by double-clicking on the file on most platforms. If you need better integration (such as a custom icon), you will need to bundle it up further into an OS-specific executable. But for starters, a simple runnable jar works fine.
send it to someone who knows nothing about java
You need to get them to at least install the Java runtime on their machine (if it is not already there).
Just to be clear, "command-line" and "knows nothing about java" are probably not going to work very well for you given that:
java is OS agnostic, therefore, if you send (presumably) a jar file to say...your grandma and she has a mac and you have a PC chances are her getting it to work is not going to be "out of the box easy" so to speak.
Left with this, I think you have a couple choices...first off, you do need to package your classes - a runnable jar will work fine. Aside from that, you will most likely have to build OS specific scripts (batch scripts for Windows, shell scripts for unix, etc.) and you will have to hand these out with your jar file. That being said, the intended user will still need to have java installed, and the batch scripts themselves are not likely to be trivial endeavors.
Your next option would be to use JNLP. However, I don't think JNLP has a command line mode, so you will likely have to simulate a console with something like a JTextArea.
As far as I see it, your last option it to use one of the many products (not sure if there are any free ones) that package java into native code. I think Exe4j is one such example - but, like I said, I am not sure if there are any free ones and I am not sure how hard they are to use.
Best of luck, and if you can't get your jar to work you should probably move that to its own question.