I have written shell script which invokes the python code. The python code is executed via nohup
.
When the python code is executed from terminal as is nohup stdbuf -oL python3 -u pid_ watch.py > log.txt 2>&1 &
it returns output as [1] 2128
. It returns the process id.
But when same executed from shell script it return empty string. Following is the code:
#!/bin/bash
#export arguments=${@}
filepath=""
username=""
while getopts 'v:u:' OPT; do
case "$OPT" in
v) filepath=$OPTARG;;
u) username=$OPTARG;;
esac
done
program_log="$(dirname "$filepath")/$(basename "$filepath" .py)_"$username".log"
output=`nohup stdbuf -oL python3 -u "$filepath" > "$program_log" 2>&1 &`
echo "${output}"
Here output is empty string. But when ps -ef
is done it shows a python process it started with that program.
How can I resolve this to get the process id from nohup in output variable?