Hi I have a flyte task that runs a subprocess that...
# ask-the-community
a
Hi I have a flyte task that runs a subprocess that runs a binary. I want to redirect the output of the subprocess s.t. it displays in flyte logs. Is this possible?
k
Use shell task - all of this is handled for you
a
I am using a TFJob in the task config
will this still work with shell task?
or should I call the shellTask from within the other task
i.e. my task looks like:
Copy code
@task(
    task_config=TfJob(
        chief=Chief(replicas=1),
        ps=PS(replicas=1),
        worker=Worker(replicas=1),
    ),
)
def some_task_name(...):
   <download binary>
   subprocess.run(binary)
k
No , in that case just redirect stdout and stderr
a
so just by doing
subprocess.run(binary, stdout=subprocess.PIPE)?
if
binary
is a long running binary (such as a training service) will this pipe logs
y
I think you can get the stdout and stderr with
Copy code
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
k
if
binary
is a long running binary (such as a training service) will this pipe logs
yes, it will.