Triggering UNIX Script from a JAVA program

Hi I am trying to implement one program, where JAVA needs to trigger the backend UNIX script. Tried with options like

String[] cmdArray = {"/bin/ksh","-c","/SCRIPT_ABSOLUTE_PATH/sampleScript.ksh /FILE_ABSOLUTE_PATH Test_File.dat TEST E SFTP"}

When I trigger the script from front end with the required parameters, it is just printing the echo statements of the script, one exception is first echo statement which is writing to a file is also not executing.
But the commands inside the script (like rm, gpg) are not getting executed.

When I run the same script with the same parameters from the command line, I don't have any issues.


#!/bin/ksh

SCRIPT_LOG=/MY_ABSOULTE_PATH/Script.log
echo "Script Triggered at `date`" >> $SCRIPT_LOG
DIRECTORY=$1
FILE_NAME=$2
CODE=$3
ACTION=$4
TRANSFER=$5

echo "File Path : $DIRECTORY"
echo "File Name to process : $FILE_NAME"
echo "Code selected : $CODE"
echo "Action Required : $ACTION"
echo "File Transfer : $TRANSFER"

cd $DIRECTORY
echo "`pwd`"

if (test -s $FILE_NAME.pgp); then
   echo "Deleting the already existed file in server."
   rm $FILE_NAME.pgp
fi

if [ $CODE == 'TEST' ]; then
echo "I am in if"
/usr/local/bin/gpg -r "sample@abc.com" --batch --passphrase mypassphrase --output $FILE_NAME.pgp -e $FILE_NAME
echo "exiting if"
fi
echo "script completed."
exit 0

How can I make the script execute same as the one from the command line through JAVA.

My Java code and UNIX script are on same server.
AIX 6.1

---------- Post updated at 11:37 PM ---------- Previous update was at 03:35 AM ----------

ANy ideas ?

The problem is: the java creates a child process that does not have environment variables like you would expect.

The script java executes has to source the startup files in your account (or where ever) to define PATH, and other important environment variables. This is a problem with the script, not necessarily java.

Example:
Use the dot operator . /path/to/.profile