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.
Related
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.
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 wanted to know is there any way I could control the name the process my jar is starting, i.e,
I created a .jar file in java and whenever I am clicking on it, it is causing a process named javaw.exe and I want to control this name.
I want to do so because when I click on my jar file then if it already running it should stop and a new one should start, i.e., I want to run a new thread (process) everytime I click on it by stopping the previous one.
If I kill the process named javaw.exe, all processes with name javaw.exe would die (if I am running more than one program) . So, I need to change its name.
Plz help.
Thanks !
There's nothing wrong with javaw running. From the documentation:
The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails for some reason.
Ultimately, javaw runs your program without a console window. Changing that name could lead to some serious issues later, so you'd want to keep that particular program name.
Why reinvent the wheel? There are already standard ways to prevent two copies of the same program from running. Typically it involves creating a "flag" file, since filesystems guarantee that directory updates are atomic. On UNIX-like systems, the file would be /var/run/program-name.pid. If it already exists, then the second copy will exit with an error.
You could setup a controller process, that manages your instances:
First you try to connect to the controller on localhost via tcp/ip at a specific port (your programs "name" from now) and if sucessful, you send a message like 'new instance started' to that controller. If the connection was not sucessful, you start a new controller-thread in the current vm (and send the message again to this thread)
the controller loops, waiting for messages and if one matches 'new instance started', it does what you describe.
such a controller can be built easily using a simple ServerSocket, a small HTTP-server or many other messaging libs.
I found a bug in an application that completely freezes the JVM. The produced stacktrace would provide valuable information for the developers and I would like to retrieve it from the Java console. When the JVM crashes, the console is frozen and I cannot copy the contained text anymore.
Is there way to pipe the Java console directly to a file or some other means of accessing the console output of a Java application?
Update: I forgot to mention, without changing the code. I am a manual tester.
Update 2: This is under Windows XP and it's actually a web start application. Piping the output of javaws jnlp-url does not work (empty file).
Actually one can activate tracing in the Java Control Panel. This will pipe anything that ends up in the Java console in a tracing file.
The log files will end up in:
<user.home>/.java/deployment/log on Unix/Linux
<User Application Data Folder>\Sun\Java\Deployment\log on Windows
/~/Library/Caches/Java/log on OS X
(If you can modify the code) you can set the System.out field to a different value:
System.setOut(new PrintStream(new FileOutputStream(fileName)));
If you are running a script (invoking the program via java) from Unix you could do:
/path/to/script.sh >& path/to/output.log
In Mac 10.8.2 logs could be found at /Users/<userName>/Library/Application Support/Oracle/Java/Deployment/log/.
Before you have to enable logging from Java Control Panel. Option "Enable logging" is at tab "Advanced". Java Control Panel could be started from "System preferences".
A frozen console probably means a deadlock (it could also mean repeated throwing of an exception). You can get a stack dump using jstack. jps may make finding the process easier.
try this guide it works for me. it also guides you that how you can set "System.setOut(fileStream);", "System.setErr(fileStream);"
We are required to add export DISPLAY=:0.0 in tomcat's startup file and batch server's startup file. This is to make java see the X11 Display libraries on Unix and run our applet. Without this export in the startup files, the applet throws a Headless Exception.
Though this explicit export makes the java applet run, it disrupts the other applications running on the server. Is there a way where I can make this export DISPLAY=:0.0 run from within java code instead of adding it to startup files? And if it is possible, would that be a good approach?
I have already tried setting the system property to -Djava.awt.headless=true , but it didn't work. As the link given above http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ also says that setting headless=true would work only for few components like Canvas, Panel but it will not work for the top level components.
So I feel the only option left for me is using export DISPLAY=:0.0. This is making my applet work when set in the startup files but causes problem for other applications running in the server. So if anybody could help me to make export DISPLAY=:0.0 work such that it doesn't interfere with other applications in the server. One way I thought was to export the display through code.
Any help would be highly appreciated.
I believe you can actually set the system property -Djava.awt.headless=true which will allow access to the graphic libraries without actually needing a display.
See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ for more info.
From your question it seems that there is something seriously wrong with your configuration.
Tomcat should always be able to run server-side without a display.
Applets always run in browser and get the x11 environment from the browser. The applet's jar could be served by tomcat, or apache, or something else, but that's irrelevant.
If your applets communicate with the server, make sure that the server code is completely separate from your applet code (keep them in separate projects) and that it doesn't use any awt code. If it does (for image manipulation, etc.), then use -Djava.awt.headless as jdewald said.
How is this affecting other applications? How are you defining the environment variable in your start up scripts? If you're defining the variable correctly, it should only affect programs started by your start up script, i.e., Tomcat and the batch server.
Also, your original question doesn't really add up. Are you running both the server and client (Tomcat and the web browser) on the same machine?