]> git.taranathan.com Git - FRC2026.git/commitdiff
Print stdout and stderr for opi shutdown
authorTimofei <108955303+TimofeiNikiforov-972@users.noreply.github.com>
Sat, 18 Oct 2025 22:23:47 +0000 (15:23 -0700)
committerTimofei <108955303+TimofeiNikiforov-972@users.noreply.github.com>
Sat, 18 Oct 2025 22:23:47 +0000 (15:23 -0700)
src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java

index 7817ef98037d686ab65409c80d285d96f50a0eb3..1b5916a1385eea9edbb97469e7efd4cd20af9484 100644 (file)
@@ -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();