cocool97 / adb_client

Rust ADB (Android Debug Bridge) client library
95 stars 19 forks source link

Is it possible to capture the output from `shell_command`? #7

Closed therealevanhenry closed 1 year ago

therealevanhenry commented 1 year ago

I noticed in the implementation of shell_command that the responses from the TCP stream are being read into a buffer and then printed to stdout.

match self.tcp_stream.read(&mut buffer) {
                Ok(size) => {
                    if size == 0 {
                        return Ok(());
                    } else {
                        print!("{}", String::from_utf8(buffer.to_vec())?);
                        std::io::stdout().flush()?;
                    }
                }
                Err(e) => {
                    return Err(RustADBError::IOError(e));
                }
            }

I'm trying to capture the output when I execute a command via shell_command but since the implementation returns an empty Ok(()) Result, there is no handle to stdout nor a handle to the buffer. What is the recommended way to capture this output for later use?

farss commented 1 year ago

I need this feature too.