r-lib/processx

Is it expected that passing a file path to `stdout` doesn't respect `wd`?

Zedseayou opened this issue · 2 comments

library(processx)
# Set up a simple file structure
run("mkdir", "test_dir") -> x
run("touch", "test_file_1") -> x
run("touch", "test_dir/test_file_2") -> x
# Try to run ls inside the created directory
run("ls", wd = "test_dir", stdout = "ls_out") -> x
cat(run("ls")$stdout)
#> ls_out
#> test_dir
#> test_file_1

This was a surprising behaviour to me when I realised what was happening. Passing the output of the command to a file using the stdout argument does not respect the wd setting. In this situation, I had expected the file ls_out to be written to inside test_dir, rather than in the working directory as actually happens.

I could see this either way. On the one hand, I was using this as a drop in replacement for cd test_dir; ls > ls_out, where ls_out is clearly written to test_dir. On the other hand, it makes some sense that the stdout argument should be in reference to the working directory of the user calling run(), not the process being created. I think a brief documentation mention might help clear this up?

It is expected, mainly because stdout predates wd. Do you want to submit a PR to the docs? (No pressure.)

sure, I can put something together!