From c4493f07f5ba77fd43926b910dbf4d9f4f2b4b01 Mon Sep 17 00:00:00 2001 From: Timofei <108955303+TimofeiNikiforov-972@users.noreply.github.com> Date: Sat, 18 Oct 2025 15:23:47 -0700 Subject: [PATCH] Print stdout and stderr for opi shutdown --- .../commands/vision/ShutdownOrangePi.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java b/src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java index 7817ef9..1b5916a 100644 --- a/src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java +++ b/src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java @@ -1,13 +1,12 @@ package frc.robot.commands.vision; -import java.nio.file.CopyOption; -import java.nio.file.FileSystems; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.PosixFilePermissions; -import java.nio.file.attribute.UserPrincipal; -import java.nio.file.attribute.UserPrincipalLookupService; import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj2.command.Command; @@ -48,9 +47,8 @@ public class ShutdownOrangePi extends Command { Path initalPathPath = Path.of(initialPath); String binPath = "/home/lvuser/sshpass2"; Path binPathPath = Path.of(binPath); - //copies to be able to get executable permissions on the new binary + // copies to be able to get executable permissions on the new binary Files.copy(initalPathPath, binPathPath, StandardCopyOption.REPLACE_EXISTING); - Files.setPosixFilePermissions(binPathPath, PosixFilePermissions.fromString("rwxr-xr-x")); String[] commandString = new String[] { @@ -69,6 +67,29 @@ public class ShutdownOrangePi extends Command { } } + @Override + public void execute() { + if (this.process == null) return; + + try { + InputStream stdout = this.process.getInputStream(); + InputStream stderr = this.process.getErrorStream(); + + int remainingStdoutBytes = stdout.available(); + int remainingStderrBytes = stderr.available(); + + if (remainingStdoutBytes > 0) { + byte[] stdoutBytes = stdout.readNBytes(remainingStdoutBytes); + System.out.println("OPI: " + new String(stdoutBytes, StandardCharsets.UTF_8)); + } + + if (remainingStderrBytes > 0) { + byte[] stderrBytes = stderr.readNBytes(remainingStderrBytes); + System.err.println("OPI: " + new String(stderrBytes, StandardCharsets.UTF_8)); + } + } catch (IOException e) {} + } + @Override public boolean isFinished() { return this.process == null || !this.process.isAlive(); -- 2.39.5