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.
Related
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 1 year ago.
Improve this question
I've got an install4j program which contains 2 launchers, 1 GUI launcher and 1 command line interface launcher.
Currently the program uses a single bundle archive to install on macOS and it would very time consuming to change this. I was wondering if there was any way I could add some sort of path variable or symlink which would allow users to run my CLI launcher anytime from terminal. (The GUI launcher is installed and set up perfectly already!)
Modifying the PATH environment variable is not easily possible on macOS and a change like that might not be appreciated by some users.
I would recommend adding symlinks to /usr/local/bin, that directly is already in the path. You can do that with "Create a symbolic link" actions.
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.
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.
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.
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
Problem: I can not understand the meaning of the question and another doubt which is generated from the above problem is that all the java software which i am using are come with executable setup so i am little bit confused from this.
Thank You
Because exe's have to be compiled for specific environments.
Oracle compiles their runtime (JRE) for different operating systems, which interprets your Java file anywhere that has a JRE installed. You can however make an installer for it:
Create Windows Installer for Java Programs