I am running a python script which runs a shell command.
Aim: To let the command run in background – collecting the logs and the python script performs next step and exits fine without hindering the shell command.
Here are the approaches I tried:
Method 1
command=f"nohup ./run.sh > runLog/nohup.out &"
subprocess.Popen(command, shell=True)
It waits for the process to finish but that brings my python script on hung state and not able to perform the next steps.
Method 2
command=f"nohup ./run.sh > runLog/nohup.out 2>&1 &"
os.system(command)
It runs the program and exits the script successfully but no log file is generated, which is not what I want.
Can you help me on how to resolve this?