Is it possible to create for only one process two different CLI (CommandLineInterface)?
I would like to have one CLI with my real program, and another CLI for a chat, so that i can send command to my program and send messages in the chat at the same time, and obviously have different views for the program and the chat.
(edit)
the program is a game and the chat is to make communication between all player, but when i start my program in eclipse, that program strat with only a console and here i would like to have two console in one there is the game with its action and state and in the other one i would like to have all the messages in the chat.
I know that i can build another process from zero and integrate it with process builder, but i would like to have all in one process.
If I assume that by CLI you mean the main terminal from where you execute your program, the answer is NO, regardless the OS.
There are couple of options to implement additional CLI interfaces in the same process:
listening on socket and waiting for client(s) to connect by e.g. telnet
opening a window that implements the CLI
under UNIX you can spawn e.g. a xterm and process its IO in your process
Under Linux or OSX, just open a new terminal window, and you will have an additional CLI to work with, and yes, you can try your program from those two different environments simultaneously and independently.
Under Windows, I couldn't say. You're probably using cygwin or something like that, so you should probably try to be a bit more specific in your question to get more attention.
Related
Relatively new to this but, I was planning to write a simple android application which can run and execute simple terminal commads like ssh, change directories etc. But i want to create buttons for each command. so (cd..) command will be a button, (mkdir) will be another. The main idea is to connect to a Linux server and then execute these commands on them, I would also use some commands which start services or kill services.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
Thanks in advance.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
No, unless you count Socket.
Instead, you would need to find an SSH client library for Android, or perhaps for ordinary Java (and hope that it runs unmodified on Android).
So i am trying to build a simple application to show concurrency in java. I wanna open 3 console windows so that i can get input output from all of them. How can do this?
Edit:I have 3 threads, each thread has its own set of cache. I wanna run 3 consoles separately in java.
i opened command prompt using Runtime class and tried attaching input and outputstream to it. But failed writing or reading from that newly opened console.
In most OSes, a process can open only one console.
You could create multiple processes and communicate between them, but that would show interprocess communication rather than inter-thread communication.
On Windows, you could try spawning child processes using 'more' or 'copy con' commands and writing to their input stream, or run your own java client which just echos input to output.
You could also create multiple JFrames and record the output of the threads in them, but again a given process has to do all its swing updates in the one swing thread, so the different threads have to sync when they output.
You're probably better off writing to the same console with different prefixes; output to the screen is always going to be a single thread in current OSes.
I have a .jar runnable running on my server. When I run the file locally I am able to see its output via my IDE. Similarly I can connect via SSH and run the file and see the output, but when I close the session the JAR exits.
Is there any way to have my application continuously running and then tapping into the java applications output using a terminal service like SSH without having to stop/start the application.
Any help would be appreciated.
You can use either screen or nohup
What is happening is that when you close your SSH session, there is a hangup call made to the program.
You could use nohup. Nohup stands for "no hangup"
nohup java -jar myJar.jar > outputFile.txt
That would run the program in the backround and send all output to outputFile.txt. When you end your session it will continue running. You must use a kill command to kill it.
The second option is you could use screen which essentually creates a detachable "ghost session". When you run screen it looks like you are in a different ssh session. Then when you detach from screen, the processes continues in the backround. When you exit your ssh session, screen continues to run.
You simply ssh back into the server, and re-attach to your screen session, and like magic, your program is still running with all relevent output. A simple read on the man page should catch you up on how to do this.
man screen
Lastly, I decided to add this third option, not because its viable, but simply so you can understand that it is an option. (Some people would claim this is the only REAL option as it is what your SUPPOSED to do. Frankly I couldn't care less and think you should do whatever is the easiest to get to your goal.)
You can also edit your program to swallow the hangup signal. The program would then always run in the backround. You can then use
java -jar myJar.jar & > outputFile.com
The & tells the command to start a new process (aka run in the backround) and the > sends the output to a file. This is how normal server applications like tomcat or spring boot work. They simply swallow the hangup call.
I've a closed-sourced Windows XP GUI-based that performs some measurements.
My current manual workflow is:
Start the data capture by clicking on the "Run" button on the GUI
Stop the data capture by pressing the "Stop" button on the GUI.
Read some value displayed on the screen.
Save the data for the session to a file.
There is no library or API to automate this whole interaction and therefore I've no option but to do it manually :( and I'm sick of it !
As you clearly see that this approach is not only time-consuming but also error prone because it is limited by my reaction time which varies with every run.
I was wondering if there is a way to automate this interaction? If yes, what are my options? I would prefer to implement something in Python or Java. But I'm open to other options as well.
My idea is to implement a server process that runs on the Windows XP machine. I can then remotely send requests to this server process which in turn will execute my workflow automatically.
There's an amazing windows GUI automation tool called autoit. http://www.autoitscript.com/site/autoit/
You asked about linking AutoIt with Java. For my purposes, I've done this using a ProcessBuilder to create a Process, then get the Processes InputStream and ErrorStream and be sure to handle these streams in a separate thread. I have AutoIt communicate with my Java program using the InputStream. A good article for this (though a little out of date) is this one: When Runtime.exec() won't. It is key to be sure that the process be run on a background thread and that the two streams be read in their own threads. If you're doing this in a Swing GUI, then extra care must be taken that all Swing calls be made on the main Swing event thread, the EDT.
I am creating a program using Java Sockets in which I capture the client desktop and send messaging to client. Its working properly but now I want to block Client applications like Notepad, MS-Word, etc.
How can I do this?
Thanks.
It is hard to do using pure java API.
I do not know what do you mean when you say "block". The easiest way is to check from time to time running processes and kill one named "notepad" by executing taskkill from java.
If you wish to achieve effect of inactivity of application, i.e. user sees the notepad but cannot type you can do the following.
You have to check which application is on front. There is no clean pure java solution for this but you can probably write VBScript or JScript that does this task and run it from java. Once you detected that notepad is on top create transparent window (or even probably half-transparent window) that occupies full screen. Bring it on top. User will not be able to type into notepad because your window is on top but will see it.
Here is reference how to create transparent windows: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
Good luck.