1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! `exec:` service — raw, binary-clean command execution.
//!
//! The device runs every `exec:` on a PTY in raw mode, which does not
//! echo input and does not perform CRLF conversion, so stdout is
//! suitable for binary payloads (e.g. `exec:cat /data/local/tmp/file`).
//! [`shell::v1`](crate::shell::v1) gets the same mode for a command, but
//! not for an empty `shell:`, where `exec:` stays raw.
//! Like [`shell::v1`](crate::shell::v1), framing is absent — stdout and stderr are
//! interleaved on the channel and no exit code is reported. For exit
//! codes or separate streams use [`shell::v2`](crate::shell::v2) on
//! devices that advertise `shell_v2`.
//!
//! Two destination forms:
//!
//! * `exec:` — start the default shell (raw PTY, stdin open).
//! * `exec:<command>` — run a single command via `sh -c`; the channel
//! closes when the command exits.
//!
//! `command` is shell source and reaches the device verbatim: see
//! [`shell::v2::exec`](crate::shell::v2::exec) on quoting it. The
//! argv-shaped APIs quote for you, but they run one program each:
//! [`cmd`](crate::cmd) and [`abb`](crate::abb) run Android's `cmd`,
//! [`logcat`](crate::logcat) runs `logcat`.
//!
//! Zero-alloc: [`Exec`] wraps an open [`Channel`](crate::channel::Channel)
//! and all destination strings and output bytes land in caller-provided
//! byte slices. Use [`open`] for streaming use and [`exec()`] for a
//! one-shot command that collects output into a single caller-owned
//! buffer.
use crateReadToEnd;
use crate;
use crateSession;
use crateError;
/// An `exec:` session: the same frameless byte stream a `shell:`
/// channel carries, always over a PTY in raw mode. Construct via
/// [`open`].
pub type Exec<'a, S> = crateShell;
/// Open an `exec:` channel and wrap it in an [`Exec`] session.
///
/// Pass an empty `command` to start the default shell; pass a command
/// string to run it via `sh -c` and have the channel close on exit.
///
/// `dest_buf` is a caller-owned scratch buffer used to assemble the
/// `exec:<command>\0` destination string. It must be at least
/// `command.len() + 6` bytes long; [`Error::ReceiveBufferFull`] is
/// returned otherwise. The buffer is free for reuse after this call
/// returns — opening copies the destination internally.
///
/// The channel borrows `session`, so only one exec session can exist
/// at a time over it. A split connection runs several at once, each over
/// its own clone of the [`Writer`](crate::Writer).
pub async
/// Run a one-shot command over `exec:` and accumulate the combined
/// stdout+stderr bytes into `buf`.
///
/// Returns the number of bytes written to `buf` once the device closes
/// the channel. Returns [`Error::ReceiveBufferFull`] if the output
/// exceeds `buf.len()` (the already-read bytes stay in `buf[..tail]`
/// but the remainder of the output is lost). The same buffer is also
/// used transiently to build the `exec:<command>\0` destination string
/// before any output arrives.
///
/// Note: `exec:` provides no exit code. If the caller needs one, use
/// [`shell::v2::exec`](crate::shell::v2::exec) on devices that advertise
/// the `shell_v2` feature.
pub async