You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-1
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,47 @@ You can execute a command through SSH using the following code:
44
44
let stdout =tryawait client.executeCommand("ls -la ~")
45
45
```
46
46
47
-
The `executeCommand` function accumulated information into a contiguous `ByteBuffer`. This is useful for non-interactive commands such as `cat` and `ls`. Citadel currently does not expose APIs for streaming into a process' `stdin` or streaming the `stdout` elsewhere. If you want this, please create an issue.
47
+
Additionally, a maximum responsive response size can be set, and `stderr` can be merged with `stdout` so that the answer contains the content of both streams:
48
+
49
+
```swift
50
+
let stdoutAndStderr =tryawait client.executeCommand("ls -la ~", maxResponseSize: 42, mergeStreams: true)
51
+
```
52
+
53
+
The `executeCommand` function accumulated information into a contiguous `ByteBuffer`. This is useful for non-interactive commands such as `cat` and `ls`.
54
+
55
+
The `executeCommandPair` function or `executeCommandStream` function can be used to access `stdout` and `stderr` independently. Both functions also accumulate information into contiguous separate `ByteBuffers`.
56
+
57
+
An example of how executeCommandPair can be used:
58
+
59
+
```swift
60
+
let streams =tryawait client.executeCommandPair("cat /foo/bar.log")
61
+
62
+
fortryawait blob in answer.stdout {
63
+
// do something with blob
64
+
}
65
+
66
+
fortryawait blob in answer.stderr {
67
+
// do something with blob
68
+
}
69
+
```
70
+
71
+
An example of how executeCommandStream can be used:
72
+
73
+
```swift
74
+
let streams =tryawait client.executeCommandStream("cat /foo/bar.log")
75
+
var asyncStreams = streams.makeAsyncIterator()
76
+
77
+
whilelet blob =tryawait asyncStreams.next() {
78
+
switch blob {
79
+
case .stdout(let stdout):
80
+
// do something with stdout
81
+
case .stderr(let stderr):
82
+
// do something with stderr
83
+
}
84
+
}
85
+
```
86
+
87
+
Citadel currently does not expose APIs for streaming into a process' `stdin`. If you want this, please create an issue.
Copy file name to clipboardExpand all lines: Sources/Citadel/TTY/Client/TTY.swift
+11-4
Original file line number
Diff line number
Diff line change
@@ -165,10 +165,11 @@ final class ExecCommandHandler: ChannelDuplexHandler {
165
165
}
166
166
167
167
extensionSSHClient{
168
-
/// Executes a command on the remote server. This will return the output of the command. If the command fails, the error will be thrown. If the output is too large, the command will fail.
168
+
/// Executes a command on the remote server. This will return the output of the command (stdout). If the command fails, the error will be thrown. If the output is too large, the command will fail.
169
169
/// - Parameters:
170
-
/// - command: The command to execute.
170
+
/// - command: The command to execute.
171
171
/// - maxResponseSize: The maximum size of the response. If the response is larger, the command will fail.
172
+
/// - mergeStreams: If the answer should also include stderr.
letstream=AsyncThrowingStream<ExecCommandOutput,Error>{ continuation in
@@ -258,7 +262,10 @@ extension SSHClient {
258
262
259
263
return stream
260
264
}
261
-
265
+
266
+
/// Executes a command on the remote server. This will return the pair of streams stdout and stderr of the command. If the command fails, the error will be thrown.
0 commit comments