I wrote an application in java that needs five players and a server.
I need to write a script that executes the jar of the server and of every single player in different terminal windows. How can I do?
I tried a script and worked but the jar opened in the same terminal window than I tried with xterm or konsole with flag --noclose but does not work (warning command: konsole not found)
#! /bin/sh
xterm --hold -e java -jar /Users/Marco\ 1/Documents/ing-sw-2019-Lentini-Marazzi-Marini/out/artifacts/server_jar/adrenalina.jar
for X in $(seq 5)
do
konsole --noclose -e java -jar /Users/Marco\ 1/Documents/ing-sw-2019-Lentini-Marazzi-Marini/out/artifacts/client_jar/adrenalina.jar gui
done
exit;
To run a process in the background from bash, you'll need to add an & to the end of your command, e.g.
java -jar /path/to/jar/my.jar &
Otherwise bash will wait until the command execution terminates.
Related
I'm working with rooted android tablets and I want to execute shell command lines. However, I've seen they stop if the command launcher app stops. If there any way to keep the execution of the shell commands despite the originator app stops?
Thanks
This is exactly what I want to execute. I want to be able to update my app inside my app:
cmd I want to execute inside my App:
am force-stop myapp & install newVersionOfMyApp.apk & monkey -p myapp 1
Then when first part of the command is executed, rest is not executed. I've seen this can be solved in other OS by modifying the command (windows add a "cmd" and linux add "&" at the end). Does Android have any equivalent way?
Finally I found the solution. You can do this by putting it after a nohup command:
nohup sh -c 'am force-stop myapp && install newVersionOfMyApp.apk && monkey -p myapp 1' &
EDITED with information of #syslogic
You'd need to detach the TTY from the console with an & (behind the command); while when the command has exit 0 (success) or exit 1 (error), the execution will halt nevertheless. running cron-jobs wouldn't require any console, at all. What I'm basically trying to tell is, that you probably should reconsider the way of how to put the commands there - while adb shell or cron does not require any GUI.
there also is adb shell monkey - while the MonkeyRunner might have (meanwhile) been replace with the UI Automator from the Support Library.
it's Monkey vs. UI Automator.
I'd write it about like this, in bash - on a PC - with ADB:
adb install -r com.acme.apk && adb shell monkey -p com.acme.AppName -v 500
I am using ubuntu 14.04
I am running a jar file which should be collection a large amount of data for a few days.
I am running the jar file thought this command and it works fine.
java -jar xxx.jar
However when i close the putty, the process stopped. Is there a way for a jar file to run even when i close the putty?
You can use nohup to run the jar(any process) in background.
Use the following command in the putty session :
nohup java -jar xxx.jar &
You need the nohup command. This command makes processes keep running despite closing terminal.
Run your jar with (in case you are in the right folder):
nohup java -jar xxx.jar &
I would suggest to you use
nohup java -jar xxx.jar > /dev/null 2>&1 &
which redirects standard error & output of the command to /dev/null which means it's discarded. If you need the console output of this command then you can redirect it to any file as follows
nohup java -jar xxx.jar > output.log 2>&1 &
I have built a Java project using Gradle. It is working fine. I have to run this project on Linux and I want to do it without the terminal window.
If I close the terminal, the project terminates.
How can I run the program without the terminal window?
You can use the nohup command:
nohup <your_command_line> >Output.log 2>&1 &
I found answer to my question . My command is 'gradle runEngineWithMonitoring'.
I can now run this process in background, even after close of terminal in linux by following below steps.
Run
gradle runEngineWithMonitoring &
command.
after this run
disown
command.
Is there a way to run basically: java -jar file1.jar, file2.jar (Using only that one command, not using it twice in a row?)
Or using java -cp file1.jar file2.jar (Again, using the command only ONCE to run TWO .jar files?)
(Using Cmd Prompt/Terminal/etc)
If so, how?
java -classpath <your path>\file1.jar -jar file2.jar
Idea is provide one jar as primary jar and everything else can go to class path.
You can use nohup for this:-
nohup java -jar file1.jar & && nohup java -jar file2.jar &
Explanation:-
* nohup is used to run the bash commands back ground(Ex:- nohup ls &).
* && is used to combine two bash commands into a single command but run both
the commands
* Here I am trying to combine and run two background processes.
You can see these processes running using the bash command "top" and checking appropriate process no.
Hope this helps!
If you want the processes not to run in background and if you want to see the output live use this bash Command!
java -jar file1.jar & java -jar file2.jar &
Hope this helps!!
I have a Java program Desktop/testfolder/xyz.jar on a remote machine. It has a configuration file on the same folder. When I SSH into the machine, I do:
"ssh user#remote java -cp Desktop/testfolder/xyz.jar Main"
The problem here is the configuration file is not in the path, as we are in the home folder so my program cannot read the configuration.
I want to first go into that folder and then run the program from that folder. In a shell script if I did this
"ssh user#remote cd Desktop/testfolder"
"java -cp xyz.jar Main"
it executes the first statement and when the second statement is run it runs on my current machine not the remote machine.
Can we do only one command or there are any other solutions for this?
Try something like this:
ssh you#yours.com "cd /home && ls -l"
You could try separating the commands by a semicolon:
ssh user#remote "cd Desktop/testfolder ; java -cp xyz.jar Main"
If you want to split your commands over multiple lines for the sake of readability, you could also pass the list of commands to the bash command as follows:
ssh user#remote.host bash -c "'
cd Desktop/testfolder
java -cp xyz.jar Main
'"