Running emacs remotely fails when no X11 forwarding - java

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.

Related

How can I change VSCode's default terminal

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.

How to check if a key was pressed in do-while Loop [in Java] [duplicate]

I have a console program written in Java that should respond to single key presses, but the user does not press enter.
I'm making pong.. so need the up and down keys to move the bat thing.
Alternative approaches welcome! (apart from making a GUI instead)
-- Edit:
I'm only going to run my program on UNIX systems (OSX and Linux), so I think I can put the terminal into "raw" mode with this: stty raw
When I type that into the console before running the program it works! But I need Java to do it automatically, so I tried this:
Runtime.getRuntime().exec("stty raw");
and it does nothing... probably because the JVM is just running it as a separate process and not as a process within this terminal.
I think you can't without native code and JNI. Take a look at Java Curses library:
http://sourceforge.net/projects/javacurses/

How to move Java runtime console to different terminal window?

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.

Compiling and calling command window contents in Matlab

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.

Debugging in NetBeans without changing focus

I have a program which uses the Robot class in Java to automate a bunch of keypresses and clicks. The problem I am encountering is not being able to set breakpoints on certain methods to debug because the focus would change when I skip to the next expression.
Is there a way I can bypass this by changing the default continue hotkey (F8) in NetBeans to a low-level keyboard hook that will check system wide?
The reason for this is because the macro I am designing runs too fast for me to see each action occurring. If I set breakpoints along the program, I must alt-tab to the IDE and continue to the next breakpoint, which, unfortunately, interferes with the macro.
If you need to interact with the system in a way that interferes with your program, you must separate your debugger from your program.
In other words, run the two on separate machines and do a remote debug from one machine to another.
The easiest way to do so if you don't have or want to use two machines, is to run your program in a virtual machine. A cheap solution is to use vmware player along with a Linux distribution supported by Netbeans.

Categories