I'm designing a console application for a server running RedHat. The end users should be able to run this app with any terminal of their choosing. (For example; Gnome Terminal, Putty SSH/ Telnet, MS Telnet Client and others).
In most terminal applications there's nothing wrong, however when I launch my program from a MS telnet session I notice my special inputs for System.in and System.console() get totally messed up. A backspace will write ^H to the screen and other keys write gibberish as well.
I've hacked at it enough that I can get it to consistently work, but I'm sure what I'm doing is gross:
if (!System.getenv("TERM").equals("xterm"))
{
System.out.println("\nWARNING: The TERM type is now set to xterm\n");
final String[] cmd = { "/bin/sh", "-c", "export TERM=xterm" };
Runtime.getRuntime().exec(cmd);
}
Would there be an issue here for terminals that don't support xterm? I notice that the Microsoft Telnet client doesn't allow you to set the TERM type to xterm before you begin a session. Once the session is started, however, setting TERM=xterm seems to solve the problem.
How do most console applications go about this issue?
With character terminal applications, there are always two ends in the communication, which must agree on how to interpret the control characters. Usually both sides are capable of using a variety of codings described in termcap/terminfo database.
On the Unix server-side you can define the coding by setting the TERM environmental variable, or by using stty (a default is used otherwise, often a dumb terminal emulation).
On the client side you also have to set the same terminal emulation as on the server side. Windows native telnet has the capability to define the emulation (see e.g. Configure the Telnet Terminal Type), as have other terminal emulators (e.g. Putty), too.
Regarding your design decisions: The above terminal setting are usually only described in user documentation, and not hardcoded in application, to leave more flexibility. After all, you do not know in advance which terminal (only a simple hardware terminal, supporting a single termcap coding, perhaps?) your users are going to use.
(As your question has little to do with Java or system.in, so you could re-consider the tags you use.)
You should look into these two posts, as they are related to what you are doing.
check env variable
set environment variable
As you are running the console on top of the Unix server, redhat in your case, I would also recommend that you look into the Unix command expect, that allows you to read the input in the console application, and performs the action according to the input of the user.
Here are some examples of the command usage.
sample Expect usages
Related
The new "Prefer Tabs" system setting in Mac OS X 11 (Big Sur) causes issues with Java applications. If the setting is set to "Always", or to "In full screen" and the application is running in full screen, JDialogs open as tabs and become unresponsive.
There is a way to set the "Prefer Tabs" setting on a per-application basis. For example, running
defaults write net.java.openjdk.cmd AppleWindowTabbingMode manual
in Terminal makes sure that NetBeans (and, seemingly, any application running on openjdk) works correctly.
Our application still supports Webstart on Mac. The above setting does not affect Webstart, so the problem still occurs there. I am not sure where the "net.java.openjdk.cmd" in the above command comes from, and where I can find the equivalent value for Webstart. It doesn't appear to be in Info.plist. Does anyone know what the value should be for Webstart (build 1.8.0_271-b09)? In general, how can I find the appropriate value for a specific application?
[Edit March 25 2021]
In an attempt to minimize burden on our users, my approach is to read the current setting using "defaults read X AppleWindowTabbingMode" from within our software. If it isn't set to manual, the software offers to run "defaults write X AppleWindowTabbingMode manual" and suggests that the user needs to restart the software afterwards.
In an attempt to get the bundle ID programmatically, I tried:
URL u = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().toURL();
URL canonicalHome = new URL(u.toString() + "jnlp");
appID = "com.oracle.jnlp-" + canonicalHome.hashCode();
but this doesn't seem to get me the right value. As far as I can tell, webstart actually uses something called JavaAppletPlugin which uses a 'java' executable, rather than 'javaws'. Any thoughts on how to programmatically get the right value?
Hope this is still relevant for you.
What you need is the bundle identifier for your app.
For openjdk this is:
<dict>
<key>CFBundleIdentifier</key>
<string>net.java.openjdk.cmd</string>
...
My guess is that a Webstart app is using javaws from the Oracle JVM.
In that case, the bundle identifier is a concatenation (from java source code):
this.bundleIdentifier = "com.oracle.jnlp-" + paramLaunchDesc.getCanonicalHome().hashCode();
You should try to create a shortcut for your app which should contain the bundle info in plist format. Get the identifier.
Then your Terminal command would become:
defaults write com.oracle.jnlp-<something> AppleWindowTabbingMode manual
Update
You might be able to find the identifier using the Java console. Enable it in the Java Control Panel which you can reach via System Preferences.
In the console, look for a log message like:
temp: bundleIdentifier is com.oracle.jnlp--<number>
Obviously it might differ for each installation :-( so you still have to find out exactly how java creates the identifier.
I have a bit of a (at least for me) odd problem. I have created a (Java) Application which (when some conditions are meet) runs a PowerShell script that uses MS-Word to print some document. I run this application through a simple batch file (java call).
It works like a charm when I run the application through my batch, BUT when I (using NSSM or AlwaysUp) turn it into a windows service the and trigger the printing process it fails. I see in the task manager that a MS-Word process is started, and it take away lots of CPU, but it does nothing (no matter how long I wait).
Simplified code:
$objOffice = New-Object -comobject Excel.Application
$objDoc = $objOffice.Workbooks.Open("C:\printTest\printFile.xlsx")
$objDoc.printout()
$objDoc.Close($false)
$objOffice.quit()
I have tested this on other computers as well... Same result.
Also interesting:
EDIT: This part written where was my fault, and fixed it.
At this point I am not even sure that it has something to do with the powershell command, but I am getting out of ideas.
Start-Process -FilePath 'C:\printTest\printFile.xlsx' -Verb print
Also, take a look at this page, which says
You might notice the option for “Allow service to interact with desktop”, which we mentioned earlier – by default, services are not
allowed to access your desktop unless this box is checked, and this
checkbox is really only there for legacy support.
But just checking
that box doesn’t immediately give them access – you would also need to
make sure that the NoInteractiveServices value in the registry is set
to 0, because when it is set to 1, that checkbox is ignored and
services can’t interact with the desktop at all. Note: in Windows 8,
the value is set to 1, and interactive services are prohibited.
I was recently trying to make a Swing GUI to send and receive commands from a third party command line program. I used the same procedure as used and working for Command Prompt, i.e., ProcessBuilder class to execute and then used BufferedReader to read responses from the program. I can surely mention it again that I could read some response, at least, from the Windows command prompt(sometimes I needed to use a Scanner in stead). When I used the same on this command line program,
It didn't show up
It didn't respond to either BufferedReader or Scanner.
I searched the internet and found a monotonous reply from it that executing the same procedure on them both is not the same thing because they are not the same things. I have not been able to complete my project till now, but I can sleep a little more at ease if I get to know what is the difference between them, their execution, aren't they same, is there any way in which we can actually bring them together and that my problem can be solved?
Most likely the program starts its own shell and does no longer interact with the original one. (You would notice this if the program opens a new window)
Or the program needs some specific library to be present to be able to interact with a shell (readline seems to be the case here) and that is not present in your Java Environment.
As a quick hack you might try to start bash (or cmd) that then starts the tool. bash and cmd have readline library. I don't have a windows ready here but as a guess just try to call your program like cmd urjtag.exe instead of just urjtag.exe that way you start a cmd process (with that you can interact) and that cmd starts the urjtag.exe where you already know that it can interact with.
Either way the problem lies in the way the program you want to call interacts with the shell and you should ask the authors of the program how it does and how you can connect to it.
From the UrJTAG documentation:
JTAG (IEEE 1149.1) is a serial interface for testing devices with
integrated circuits.
and
UrJTAG is a software package which enables working with JTAG-aware
(IEEE 1149.1) hardware devices (parts) and boards through a JTAG
adapter.
It is not a command prompt.
It is not meant to be used as a command prompt for generic programs.
So, as other monotonous responses have already told you, it and the windows command prompt are not the same thing, even though you seem to think they are. It has a very specific use-case as described in the documentation.
The windows command prompt is a special program which invokes specific executables and passes command line arguments to them in a specific way.
The java.exe executable is designed to understand this kind of invocation.
Since the UrJTAG executable it is not a generic command prompt, it doesn't do what the windows command prompt does, and so will not work for running Java programs like you want.
I'm trying to find a way to access the IP and MAC addresses for the default gateway from a java applet to be run on a website, is this possible?
You can't do that kind of thing in Java, like getting the SSID on a Wifi network. This low-level hardware information can not be obtained in Java in a cross-platform way and Java only allow you to work in the Transport (TCP) level, aka use sockets.
If you need this kind of information, try invoking a OS command tool using Runtime.getRuntime().exec(...) and parsing the output. But you have to deal with different OS that means different commands tools and outputs.
But in the Applet world, you can't invoke OS command tools, nor opening files, you are in a sandbox that prevents Applets for doing some low-levels tasks that can put in risk the user computer.
If you sign your applet, you have privileges to perform same operations like regular desktop applications, but this is out of scope.
Try to focus you problem in another direction.
You can get the Mac Address of an interface in Java using the method getHardwareAddress in the class java.net.NetworkInterface (http://download.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress()). I am not sure if that will work inside an Applet, and I have never tested that method myself, but if something does it, this method is that thing.
The IP Address? sure thing. Just have the applet connect back to your server. An applet can open an http connection to the server that hosts it.
The MAC and Default GW are system specific things you could get via external programs, but I'm not 100% sure those are supported in the applet sandbox (in fact, they're probably not supported).
I have a really nasty problem. My java application is running on unix and I'm using VNC to connect (from windows). The problem is that VNC has some issues with registering non-ansi keysum's.
KbdAddEvent: unknown KeySym 0xc0 -
allocating KeyCode 117
Even so, keyboard input works correctly in xterm, mozilla and etc. But when I'm using java for this keycodes to work, I need first to enter them wiht my keyboard (all of them, so VNC can allocate them), and after that to start java.
So my question is, is there a way running java instance to re-read keycodes from environment, so for me to be able to use non-ansi keycodes without typing them first, and only after that starting some java application.