My Java team provided me a jar file and below command to execute in Cygwin environment:
java -DmoduleName="GBL" -jar G:/CSFBApps/planning/bin/planning_aura.jar G:/CSFBApps/planning/bin/resources
This command when I trigger from command prompt working fine but when I put the same in sample KSH script:
java -DmoduleName="GBL" -jar G:/CSFBApps/planning/bin/planning_aura.jar G:/CSFBApps/planning/bin/resources
echo $?
it just executes and showing 1 (which i think not executed).
So i believe KSH not invoking jar, please help me.
Checkout other posts showing how to use cygpath with java in cygwin
Related
I am trying to execute a jar file from a bash script, but for whatever reason, java subcommands are not working within the shell script. Attached is an example of a simple script, and the error it returns. The same error is outputted when I use any subcommand for java.
What do I need to fix?
#!/bin/sh
java -version
I created Shell Script on Linux and it runs fine.
Now I want to run the same script on Windows using gitbash. (Only filepath changed for windows)
I am confused:
do I need to write a new shell script again according to Windows syntax shell script?
or
can a Linux syntax shell script run on Windows without changes?
According TO differences-between-windows-batch-and-linux-bash-shell-script-syntax
Of course you can. There is a tool called cygwin that allows you to do so.
Note that you have to check what the paths are. If so, go to the path you are willing to work on and do pwd. This way, you will get the Windows\kind\of\path.
I use it all the time and it works pretty fine.
You can use Git Bash
It depends on how advanced the scripts are, but simple scripts can be executed in Git Bash.
test.sh contains:
#!/bin/bash
echo Hello World!
Execute script:
./test.sh
Output:
Hello World!
Git Bash vs Cygwin
To answer your question:
#fedorqui in my learning 'cygwin' And 'gitbash' do same stuff for
windows
Git Bash
Git Bash is lightweight and only aims to handle:
version control
a shell that runs commands
Read more: http://openhatch.org/missions/windows-setup/install-git-bash
Cygwin
a large collection of GNU and Open Source tools which provide
functionality similar to a Linux distribution on Windows.
a DLL (cygwin1.dll) which provides substantial POSIX API
functionality.
Read more: https://www.cygwin.com/
I am switching my server's hosting provider from Windows Server to Linux Debian and I need help to convert my Run.bat to an executable shell script.
The Windows batch file:
java -cp bin; deps/mail.jar; deps/xstream.jar; deps/xpp3-1.1.4c.jar;
deps/scheduling.jar -server server.Server
When I save this as a shell script it does not properly run when I "Run in terminal", the shell just opens and closes immediately.
In linux, the separator is : instead of ;, so try this instead:
$ java -cp bin:deps/mail.jar:deps/xstream.jar:deps/xpp3-1.1.4c.jar:deps/scheduling.jar -server server.Server
Copy the command without the $. The $ is used to indicate the command belongs in a linux shell.
When I want to execute a file, it seems that I always have to first 'cd' into that file's directory before executing it, unless it fails on a can't-find-my-dataz type error.
How can I get around typing two commands to just execute a program?
Example:
cd /usr/local/bin/minecraft/
java -Xms512M -Xmx2048M -jar minecraft.jar
How can I make that into one line, so as I can put it as my Exec=_ line when creating a custom launcher in Gnome3?
cd /usr/local/bin/minecraft/ && java -Xms512M -Xmx2048M -jar minecraft.jar should do it
I am answering this question again with some extension so that others may find this useful.
cd /usr/local/bin/minecraft/ && java -Xms512M -Xmx2048M -jar minecraft.jar
This command will do for sure. But after running this command, you will stay in /usr/local/bin/minecraft/ directory. And, if you are using this command in a bash script, all the later commands will be executed in this directory.
If you want to run the command in your desired directory and get immediately back to where you were, enclose the command with parenthesis, i.e.,
(cd /usr/local/bin/minecraft/ && java -Xms512M -Xmx2048M -jar minecraft.jar)
Alternatively (e.g. if passing somewhere else to be executed)
sh -c 'cd /usr/local/bin/minecraft; java -Xms512M -Xmx2048M -jar minecraft.jar'
I have a shell script file (run.sh) that contains the following:
#!/bin/bash
%JAVA_HOME%/bin/java -jar umar.jar
when i try to run it (./run.sh), it gives me following:
umar/bin/run.sh: line 1: fg: no job control
However if I run same command directly on shell, it works perfectly.
What's wrong with the script file?
Thanks
%foo% is not how you do command substitution in a bourne/BASH shell script. I assume you're running this from a Windows command line, which is why it works when you run it directly. Try using proper bourne syntax:
${JAVA_HOME}/bin/java -jar umar.jar
Try turning on monitor mode
set -m
%JAVA_HOME% will substitute a Windows environment variable and is appropriate in a .bat file.
Try the following shell script which should work on most UNIX like systems.
#!/bin/bash
$JAVA_HOME/bin/java -jar umar.jar