I’m trying to execute a shell script from Java code using Process Class.
Execution happens on a red hat Linux machine.
An end point calls this java code which in turn should execute the script on the Linux machine.
The Linux machine is on default ksh shell.
I’m using Process.exec(command) to run it.
Here are the commands I’m trying to run
1. sh createFile.sh
2. bash -i executePythonScript.sh -option1ToPython value1 -option2ToPython value2
Permission were given to these files to be executed using chmod.
createFile.sh
#!bin/bash
touch hello.txt
executePythonScript.sh
#!bin/bash
conda activate dev_environment
python hello.py -option1 value1
conda deactivate
The commands are working when I ssh into the machine and run them individually.
But when I do it thru java code, I’m failing.
With java code, I can run the commands like
1. cd /abc/def
2. touch hello.txt
But when I’m trying to run the same commands within a shell script, I’m failing.
Please advise.
4