r-lib / processx

Execute and Control Subprocesses from R
https://processx.r-lib.org/
Other
234 stars 43 forks source link

redirection of stdout in subjob #351

Closed sdirkse67 closed 1 year ago

sdirkse67 commented 1 year ago

I have a failure in a process that is started via process$new('dumper',stdout='|')that only happens with stdout sent to a pipe. If I take off the stdout arg things work OK. Perhaps this is an issue with processx that can be addressed. Or perhaps I am doing something wrong with my dumper code. Any insights or help appreciated.

The executable dumper.exe calls a windows batch file dd.cmd, and the batch file redirects stdout to a file. Calling dumper.exe from a Windows command prompt works, but calling it as below fails:

p = process$new('dumper',stdout='|')
p$read_output()
[1] "dumper:  inheritHandles=0  useStdHandles=0  \r\n exitcode: 1 \r\n"

The redirection inside the cmd file fails: this is reflected in the exitcode of 1. If I adjust dumper.c to run with inheritHandles=TRUE and leave the USESTDHANDLES bit alone, it works as hoped. But for other reasons we want to run with inheritHandles=FALSE.

dumper.c.txt

The content of dd.cmd:

@echo off
echo DD %1 %2 > dd.txt
gaborcsardi commented 1 year ago

I think this is all expected. processx sets the stdout of dumper, but if you want to start another process and receive the output of that, then that process will have to inherit stdout. I don't think processx can do anything about this.

gaborcsardi commented 1 year ago

But please tell me if I am missing something.