- Enter the following in a text file using a text editor. Naturally, substitute the name of your program and the accordant arguments. Type it exactly the way you would do it on a shell commandline.
- Today we are going to show you how to start a script and read its output in a Java program. We are going to run a windows batch file in our example but you can run a script from Linux or any UNIX.
- How to create simple Mac apps from shell scripts. Published 12th November 2010 tagged with Bash. I’m running on Mac OS X 10.7.2. My script is a simple: #!/bin/bash echo 'hello' When I appify it. I am trying to make a Java program that will dynamically create a shell scripts and write it out into this structure to make am easily.
- Running Java Programs
- Bash Script Example For Running Java Program Machine
- Bash Script Example For Running Java Program Mac
- Metaphor Example For Running
- Bash Script Example For Running Java Program Mac Terminal
- Running Java App Lets
Active5 years ago
I have to run a jar file with different parameters like this:
Tutorial – Calling Java from a Bash Script February 12, 2014 3 min read Bash is a very flexible cross-platform scripting language with multiple uses and can integrate with lots of other tools (ie DIff).
If, say, the second one took more than five minutes, I want to stop it and continue to the next one. So the maximum time for each running jar is 5 minutes. If it takes less than that, that's fine; but if one runs longer than that, the script must continue to the next one.
G-Man6,3251111 gold badges2727 silver badges6464 bronze badges
Hk148Hk148
![Program Program](/uploads/1/2/6/1/126133294/336618185.jpg)
2 Answers
This should work in bash 4 or later:
For previous versions:
After searching a bit for a pure java version, I found this:
Community♦
NuTTyXNuTTyX
If your system has the
G-ManG-Mantimeout
command, you should be able to use it, as6,3251111 gold badges2727 silver badges6464 bronze badges
Not the answer you're looking for? Browse other questions tagged bashjavajar or ask your own question.
Active4 years, 4 months ago
I've downloaded the free and open-source image analysis software 'Icy' (http://icy.bioimageanalysis.org/), and I can launch it by making the 'icy.sh' file executable and double-clicking on it.
However if I create a shortcut to this file, I can't launch it, except if the shortcut is in the original folder.Here is a clue, that this is possibly due to the fact that 'Java programs need to be started from within the directory in which their files exist.': https://help.ubuntu.com/community/HowToAddaLauncher
But I have no idea of how it actually works and how to solve that.If you have any idea that would be great :-)
Thanks guys!
Alexis CllmbAlexis Cllmb
3 Answers
when you open that icy.sh file, you can see
Running Java Programs
So you can just modify (leafpad, gedit or any other text editor)your icy.desktop file to:
With icy.sh set as executable and with shortcut created as:
it didnt work, like in your case... this is workaround I would use
RiddleMeThisRiddleMeThis
Bash Script Example For Running Java Program Machine
Create a .desktop file:
- Copy it into an empty file, save it as
icy.desktop
- Replace
/path/to/script/directory
by the actual path to the script's directory - Make it executable
Explanation
Desktop files (with the extension .desktop) can be used to perform all kinds of applications or tasks. To make it run shell commands, the format is:
![Example Example](/uploads/1/2/6/1/126133294/804448030.png)
The
<command>
in this case is:Bash Script Example For Running Java Program Mac
In detail:
to
cd
to the script's directory, and subsequently:to run
icy.sh
from its own directoryGive the .desktop file an(other) icon:
The example file is a very basic one:
Metaphor Example For Running
If you'd like the file to have another icon than the generic one, add a line (e.g.):
More on
Jacob Vlijm.desktop
files and their required/optional entries here.Bash Script Example For Running Java Program Mac Terminal
Jacob VlijmRunning Java App Lets
68.7k1010 gold badges144144 silver badges247247 bronze badges
You can open the 'shortcut' as a plain text using any text editor. When opened, you must change the path of the file. Probably now it's a relative path, so make it absolute to look like './home/user/pathtofile/file.sh'
Junk O MaticJunk O Matic