Rollback of commit 1e37a5375f918376c132fa537e25695f673f41b8.

*** Reason for rollback ***

Apparently we now try to open output files for the process twice: once when we are constructing the output streams, and the second time when we tell the process to redirect its outputs. This causes the outputs to be empty on Windows

*** Original change description ***

Do redirection of stdout / stderr in Java instead of reimplementing it in every process wrapper again.

--
MOS_MIGRATED_REVID=126801016
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 7e7575d..af217e0 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -964,7 +964,6 @@
         "//src/main/java/com/google/devtools/build/lib:build-base",
         "//src/main/java/com/google/devtools/build/lib:clock",
         "//src/main/java/com/google/devtools/build/lib:events",
-        "//src/main/java/com/google/devtools/build/lib:io",
         "//src/main/java/com/google/devtools/build/lib:os_util",
         "//src/main/java/com/google/devtools/build/lib:shell",
         "//src/main/java/com/google/devtools/build/lib:util",
@@ -992,7 +991,6 @@
         "//src/main/java/com/google/devtools/build/lib:build-base",
         "//src/main/java/com/google/devtools/build/lib:clock",
         "//src/main/java/com/google/devtools/build/lib:events",
-        "//src/main/java/com/google/devtools/build/lib:io",
         "//src/main/java/com/google/devtools/build/lib:os_util",
         "//src/main/java/com/google/devtools/build/lib:shell",
         "//src/main/java/com/google/devtools/build/lib:util",
diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
index 492425c..771162f 100644
--- a/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategyTestCase.java
@@ -29,9 +29,9 @@
 import com.google.devtools.build.lib.exec.ExecutionOptions;
 import com.google.devtools.build.lib.testutil.BlazeTestUtils;
 import com.google.devtools.build.lib.testutil.TestConstants;
+import com.google.devtools.build.lib.testutil.TestFileOutErr;
 import com.google.devtools.build.lib.testutil.TestUtils;
 import com.google.devtools.build.lib.util.BlazeClock;
-import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.FileSystem;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
@@ -56,7 +56,7 @@
   protected BlazeExecutor executor;
   protected BlazeDirectories blazeDirs;
 
-  protected FileOutErr outErr;
+  protected TestFileOutErr outErr = new TestFileOutErr();
 
   protected String out() {
     return outErr.outAsLatin1();
@@ -70,9 +70,6 @@
   public final void createDirectoriesAndExecutor() throws Exception  {
     Path testRoot = createTestRoot();
 
-    outErr =
-        new FileOutErr(testRoot.getRelative("test_out.log"), testRoot.getRelative("test_err.log"));
-
     workspaceDir = testRoot.getRelative("workspace");
     workspaceDir.createDirectory();
 
diff --git a/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java b/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
index 6d20ba7..580bff9 100644
--- a/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
@@ -39,10 +39,10 @@
 import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
 import com.google.devtools.build.lib.testutil.BlazeTestUtils;
 import com.google.devtools.build.lib.testutil.TestConstants;
+import com.google.devtools.build.lib.testutil.TestFileOutErr;
 import com.google.devtools.build.lib.testutil.TestUtils;
 import com.google.devtools.build.lib.util.BlazeClock;
 import com.google.devtools.build.lib.util.OS;
-import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.FileSystem;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
@@ -66,7 +66,6 @@
   private Reporter reporter = new Reporter(PrintingEventHandler.ERRORS_AND_WARNINGS_TO_STDERR);
   private BlazeExecutor executor;
   private FileSystem fileSystem;
-  private FileOutErr outErr;
 
   private Path createTestRoot() throws IOException {
     fileSystem = FileSystems.getNativeFileSystem();
@@ -86,9 +85,6 @@
     Path workspaceDir = testRoot.getRelative(TestConstants.WORKSPACE_NAME);
     workspaceDir.createDirectory();
 
-    outErr =
-        new FileOutErr(testRoot.getRelative("test_out.log"), testRoot.getRelative("test_err.log"));
-
     // setup output base & directories
     Path outputBase = testRoot.getRelative("outputBase");
     outputBase.createDirectory();
@@ -123,6 +119,8 @@
         new ActionsTestUtil.NullAction());
   }
 
+  private TestFileOutErr outErr = new TestFileOutErr();
+
   private String out() {
     return outErr.outAsLatin1();
   }
@@ -142,7 +140,6 @@
   private void run(Spawn spawn) throws Exception {
     executor.getSpawnActionContext(spawn.getMnemonic()).exec(spawn, createContext());
   }
-
   private ActionExecutionContext createContext() {
     Path execRoot = executor.getExecRoot();
     return new ActionExecutionContext(
diff --git a/src/test/shell/bazel/namespace-runner_test.sh b/src/test/shell/bazel/namespace-runner_test.sh
index 5c05f98..da6857b 100755
--- a/src/test/shell/bazel/namespace-runner_test.sh
+++ b/src/test/shell/bazel/namespace-runner_test.sh
@@ -49,78 +49,74 @@
 }
 
 function test_basic_functionality() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -- /bin/echo hi there >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -l $OUT -L $ERR -- /bin/echo hi there || fail
   assert_output "hi there" ""
 }
 
 function test_default_user_is_nobody() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -- /usr/bin/id >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -l $OUT -L $ERR -- /usr/bin/id || fail
   assert_output "uid=65534 gid=65534 groups=65534" ""
 }
 
 function test_user_switched_to_root() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -r -- /usr/bin/id >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -r -l $OUT -L $ERR -- /usr/bin/id || fail
   assert_contains "uid=0 gid=0" "$OUT"
 }
 
 function test_network_namespace() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -n -- /bin/ip link ls >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -n -l $OUT -L $ERR  -- /bin/ip link ls || fail
   assert_contains "LOOPBACK,UP" "$OUT"
 }
 
 function test_ping_loopback() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -n -r -- /bin/ping -c 1 127.0.0.1 >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -n -r -l $OUT -L $ERR  -- /bin/ping -c 1 127.0.0.1 || fail
   assert_contains "1 received" "$OUT"
 }
 
 function test_to_stderr() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -- /bin/bash -c "/bin/echo hi there >&2" >$OUT 2>$ERR || fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -l $OUT -L $ERR -- /bin/bash -c "/bin/echo hi there >&2" || fail
   assert_output "" "hi there"
 }
 
 function test_exit_code() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -- /bin/bash -c "exit 71" >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -l $OUT -L $ERR -- /bin/bash -c "exit 71" || code=$?
   assert_equals 71 "$code"
 }
 
 function test_signal_death() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -- /bin/bash -c 'kill -ABRT $$' >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -l $OUT -L $ERR -- /bin/bash -c 'kill -ABRT $$' || code=$?
   assert_equals 134 "$code" # SIGNAL_BASE + SIGABRT = 128 + 6
 }
 
 function test_signal_catcher() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3 -- /bin/bash -c \
-    'trap "echo later; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3 -l $OUT -L $ERR -- /bin/bash -c \
+    'trap "echo later; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "later"
 }
 
 function test_basic_timeout() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 3 -t 3 -- /bin/bash -c \
-    "echo before; sleep 1000; echo after" >$OUT 2>$ERR && fail
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 3 -t 3 -l $OUT -L $ERR -- /bin/bash -c "echo before; sleep 1000; echo after" && fail
   assert_output "before" ""
 }
 
 function test_timeout_grace() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3  -- /bin/bash -c \
-    'trap "echo -n before; sleep 1; echo -n after; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' \
-    >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3 -l $OUT -L $ERR -- /bin/bash -c \
+    'trap "echo -n before; sleep 1; echo -n after; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "beforeafter"
 }
 
 function test_timeout_kill() {
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3 -- /bin/bash -c \
-    'trap "echo before; sleep 1000; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' \
-    >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -T 2 -t 3 -l $OUT -L $ERR -- /bin/bash -c \
+    'trap "echo before; sleep 1000; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 1000' || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "before"
 }
 
 function test_debug_logging() {
   touch ${TEST_TMPDIR}/testfile
-  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -D -M ${TEST_TMPDIR}/testfile -m /tmp/sandboxed_testfile \
-    -- /bin/true >$OUT 2>$ERR || code=$?
+  $namespace_sandbox $SANDBOX_DEFAULT_OPTS -D -M ${TEST_TMPDIR}/testfile -m /tmp/sandboxed_testfile -l $OUT -L $ERR -- /bin/true || code=$?
   assert_contains "mount: /usr/bin\$" "$ERR"
   assert_contains "mount: ${TEST_TMPDIR}/testfile -> <sandbox>/tmp/sandboxed_testfile\$" "$ERR"
 }
diff --git a/src/test/shell/bazel/process-wrapper_test.sh b/src/test/shell/bazel/process-wrapper_test.sh
index 93bf4d5..a46b450 100755
--- a/src/test/shell/bazel/process-wrapper_test.sh
+++ b/src/test/shell/bazel/process-wrapper_test.sh
@@ -41,37 +41,37 @@
 }
 
 function test_basic_functionality() {
-  $process_wrapper -1 0 /bin/echo hi there >$OUT 2>$ERR || fail
+  $process_wrapper -1 0 $OUT $ERR /bin/echo hi there &> $TEST_log || fail
   assert_output "hi there" ""
 }
 
 function test_to_stderr() {
-  $process_wrapper -1 0 /bin/bash -c "/bin/echo hi there >&2" >$OUT 2>$ERR || fail
+  $process_wrapper -1 0 $OUT $ERR /bin/bash -c "/bin/echo hi there >&2" &> $TEST_log || fail
   assert_output "" "hi there"
 }
 
 function test_exit_code() {
   local code=0
-  $process_wrapper -1 0 /bin/bash -c "exit 71" >$OUT 2>$ERR || code=$?
+  $process_wrapper -1 0 $OUT $ERR /bin/bash -c "exit 71" &> $TEST_log || code=$?
   assert_equals 71 "$code"
 }
 
 function test_signal_death() {
   local code=0
-  $process_wrapper -1 0 /bin/bash -c 'kill -ABRT $$' >$OUT 2>$ERR || code=$?
+  $process_wrapper -1 0 $OUT $ERR /bin/bash -c 'kill -ABRT $$' &> $TEST_log || code=$?
   assert_equals 134 "$code" # SIGNAL_BASE + SIGABRT = 128 + 6
 }
 
 function test_signal_catcher() {
   local code=0
-  $process_wrapper 1 2 /bin/bash -c \
-    'trap "echo later; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' >$OUT 2>$ERR || code=$?
+  $process_wrapper 1 2 $OUT $ERR /bin/bash -c \
+    'trap "echo later; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' &> $TEST_log || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "later"
 }
 
 function test_basic_timeout() {
-  $process_wrapper 1 2 /bin/bash -c "echo before; sleep 10; echo after" >$OUT 2>$ERR && fail
+  $process_wrapper 1 2 $OUT $ERR /bin/bash -c "echo before; sleep 10; echo after" &> $TEST_log && fail
   assert_stdout "before"
 }
 
@@ -81,9 +81,9 @@
 # grace period, thus printing "beforeafter".
 function test_timeout_grace() {
   local code=0
-  $process_wrapper 1 10 /bin/bash -c \
+  $process_wrapper 1 10 $OUT $ERR /bin/bash -c \
     'trap "echo -n before; sleep 1; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \
-    >$OUT 2>$ERR || code=$?
+    &> $TEST_log || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "beforeafter"
 }
@@ -94,16 +94,16 @@
 # trap takes longer than the grace period, thus only printing "before".
 function test_timeout_kill() {
   local code=0
-  $process_wrapper 1 2 /bin/bash -c \
+  $process_wrapper 1 2 $OUT $ERR /bin/bash -c \
     'trap "echo before; sleep 10; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \
-    >$OUT 2>$ERR || code=$?
+    &> $TEST_log || code=$?
   assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
   assert_stdout "before"
 }
 
 function test_execvp_error_message() {
   local code=0
-  $process_wrapper -1 0 /bin/notexisting >$OUT 2>$ERR || code=$?
+  $process_wrapper -1 0 $OUT $ERR /bin/notexisting &> $TEST_log || code=$?
   assert_equals 1 "$code"
   assert_contains "execvp(\"/bin/notexisting\", ...): No such file or directory" "$ERR"
 }