How to make a remote shell gui in java [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a java program that needs to be able to connect to a remote server and execute system commands. How would I create a command shell that looked exactly the same as windows command prompt for the client, but executes the commands on the remote server? Thx in advance

It's possible to do, but it's not easy - java has never been great for command-line operation. If you want to do it, look for java-based SSH implementations.
On the other hand, if the user will be running the java program from the command-line, it may be possible to execute an ssh command on the same terminal.
Here is a page that describes executing an external program from java: http://alvinalexander.com/java/java-exec-processbuilder-process-1.

Related

Start OpenVPN from Java application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is it even possible to start OpenVPN trough Java application? If it is possible what is the best way to do it so it's cross-platform and works on all platforms that have OpenVPN installed.
You can run openvpn with Java like this:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("openvpn your_config.ovpn");
This will run openvpn via the command line. It is cross platform, too, as it will work on Mac, Linux and Windows.

Java interact with windows cmd [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I've searched for similar questions, but despite there where a lot with a similar title all have asked something different.
In my case I want that my java program interact with the terminal (Windows) by writing command and reading the response.
I've found the class ProcessBuilder, but does not seem that do what I want
What I' m searching for is something so:
start the cmd at some given position (like C:\Users\federico)
issue a command (dir or cd desktop); this should not open a command prompt window
read any output that command may result in
and so on, up to the user's exit from the program.
I suspect you simply don't know the English terms for this: what you're looking for is a way to execute commands in the OS, which is called "exec" in every programming language I know of, including Java: https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String)

Java program to build and run a maven project [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I was trying to create a java application that automatically build my project.Is it possible to create a java program to run a maven project?
You can follow below approach to start:
Create a batch/shell file to build your project using mvn/ant/gradle
command. You would need Maven/Ant/Gradle installed in your system
and environment variable needs to be setup properly.
Run This batch/shell file using java by taking advantage of Runtime
Class. Runtime.getRuntime().exec("cmd /c start build.bat");
To schedule your java program, Use ExecutorService or Quartz. Or you
can take advantage of Operating System Schedulers as well.
Hope this helps.

Run cmd command without creating a .bat file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
is there a way to execute a cmd command like "move FolderA FolderB" without creating a .bat file and start it?
It would be nice if it would work without creating files on HDD.
Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","move","dirA/a.txt","dirB"});
Process process = new ProcessBuilder("cmd.exe",
"/c","move","dirA/a.txt","dirB").start();
ProcessBuilder is preferred to Runtime.exec() since Java 1.5, according to JavaDoc.
Be sure to read the Process Javadoc to understand how to read from and write to processes.
Shelling out for commands like move is bad practice, because it's neither portable nor secure. Work with File classes instead. But sometimes you have to shell out to interact with more esoteric external programs.

Executing script file using Eclipse [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am creating one .sh file using ECLIPSE on windows machine.
How can I make that same .sh file run on Ubuntu using that same Java code
to run on linux
Runtime.getRuntime.exec("foo.sh");
The class java.lang.Runtime features a static method called getRuntime(), which retrieves the current Java Runtime Environment. That is the only way to obtain a reference to the Runtime object. With that reference, you can run external programs by invoking the Runtime class's exec() method.
To execute a .sh script on Windows, you would have to have a suitable command interpreter installed.

Categories