I currently have the following code whereby I am using os.execv()
to execute some sort of process. For example:
process_param = [exec_path, f]
pid = os.fork(
try:
if (pid > 0):
#parent
time_lim = 55
for _ in range(time_lim):
child_pid, status = os.waitpid(-1, os.WNOHANG)
if (child_pid != 0):
break
time.sleep(1)
elif (pid == 0):
os.execv(exec_path, process_param)
else:
status = 1
except ChildProcessError:
status = 1
Before you tell me to use subprocess
, please note that (for assignment purposes), I should stick to this particular method of running bash commands through Python.
I would like to do something similar to this:
var_a=`cat some_file`
Does anyone know how I can capture the output derived from the os.execv()
command (located in the child process) and store it in a variable (perhaps returning it to the parent process)?