How to run a java program from another java program? [duplicate] - java

This question already has answers here:
How to run Java code using Java code?
(4 answers)
Closed 8 years ago.
So I have a java program of a game. I want to have a different program and when you click on a button there that java program closes and starts the program with the game. But I have no idea how I can do that, so can anyone help me?

Using ProcessBuilder.The following is a reference,maybe not work.
ProcessBuilder pb=new ProcessBuilder("java","-jar","Test3.jar");
pb.directory(new File("F:\\dist"));
Map<String,String> map=pb.environment();
Process p=pb.start();

Create a runnable jar.
call the runnable jar on button click.
Exit from the current program.

Related

running a process in background in linux [duplicate]

This question already has answers here:
How to run Node.js as a background process and never die?
(14 answers)
Closed 5 years ago.
I want to run this in background.
Here is the content of my .sh file.
Please suggest me
java -Dlogback.configurationFile=logback.xml -jar report-schedule.jar $1
You can use & at the end of your shell command,
sh YourScriptShell.sh &
Or you can also use Ctrl+z and then write bg
bg for background.
To retrieve it in foreground, use fg
And that's it :)
use
nohup your_shellscript &

Using Javacode to get the actual name of the Program that is top [duplicate]

This question already has answers here:
How to get a list of current open windows/process with Java?
(14 answers)
Closed 6 years ago.
I am currently writing a Java Application, that needs to filter the name of the Program whichs UI is front. Sorry for my bad english.
So let's say the Java App is running in Background and I open Windows -> Games -> Minesweeper then i want the App to only tell me "Active: Minesweeper". Without any additional information. Just the name "Minesweeper"
I already tried using JavaNativeAccess but I'm still unfamiliar with it.
Thanks you all in advance
You might want to look at the following link which might be of help:
How to get a list of current open windows/process with Java?

how to open program (matlab) using java? [duplicate]

This question already has answers here:
Running MATLAB function from Java
(5 answers)
Closed 7 years ago.
i have project in matlab (neural network) but my GUI is using java (netbeans) and i want to open my matlab project using that GUI. can anyone show me the code to open matlab or other program using java. thanks
You'd want something like this:
Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("matlab");
process.destroy(); // to kill the app

Force Stop android application [duplicate]

This question already has answers here:
How to force stop my android application programmatically?
(7 answers)
Closed 5 years ago.
Help me!
I need the source code to force stop an Android application programmatically.
I already tried
Process.killProcess(int pid))
but it didn't work
Thank You.
Three ways to stop a process from java
1.kill directly
Process.killProcess(Process.myPid());
2.send SIG_KILL
Process.sendSignal(Process.myPid(), Process.SIGNAL_KILL);
3.the unfriendly way, terminate the vm
System.exit(0);

How to call python script form java class [duplicate]

This question already has answers here:
Calling Python in Java?
(12 answers)
Closed 8 years ago.
I have a java web app where i need to use a simple web crawler to read html from webpages. I could not find any simple solution for this in java. But got a very simple python script that solve my problem. Now how to call that python script (.py) from my java class and also get the returned value from the python script .Thanks in advance .
First check out Calling Python in Java?
Another approach might be to call the python interpreter from the command line with a Java Process. See Java Process with Input/Output Stream and Call python script within java code (runtime.exec)

Categories