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
+34-26Lines changed: 34 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -244,7 +244,7 @@ reader.readData()
244
244
245
245
All Contexts (`CustomContext` and `main`) implement `CommandRunning`, which means they can run commands using themselves as the Context. ReadableStream and String can also run commands, they use `main` as the Context and themselves as `.stdin`. As a shortcut you can just use `run(...)` instead of `main.run(...)`
246
246
247
-
There are three different ways of running a command:
247
+
There are 4 different ways of running a command:
248
248
249
249
#### Run
250
250
@@ -304,50 +304,58 @@ let command = runAsync("cmd", "-n", 245).onCompletion { command in
304
304
// be notified when the command is finished.
305
305
}
306
306
command.stdout.onOutput { stdout in
307
-
// be notified when the command produces output.
307
+
// be notified when the command produces output (only on macOS).
308
308
}
309
309
310
310
// do something with ‘command’ while it is still running.
311
311
312
312
try command.finish() // wait for it to finish.
313
313
```
314
314
315
-
`runAsync` launches a command and continues before it's finished. It returns this:
315
+
`runAsync` launches a command and continues before it's finished. It returns `AsyncCommand` which contains this:
316
316
317
317
```swift
318
-
/// Output from the 'runAsync' methods.
319
-
publicfinalclassAsyncCommand {
320
-
publiclet stdout: ReadableStream
321
-
publiclet stderror: ReadableStream
318
+
publiclet stdout: ReadableStream
319
+
publiclet stderror: ReadableStream
322
320
323
-
/// Is the command still running?
324
-
publicvar isRunning: Bool
321
+
/// Is the command still running?
322
+
publicvar isRunning: Bool { get }
325
323
326
-
/// Terminates command.
327
-
publicfuncstop()
324
+
/// Terminates the command by sending the SIGTERM signal.
325
+
publicfuncstop()
328
326
329
-
/// Waits for command to finish.
330
-
/// - returns: itself
331
-
/// - throws: `CommandError.returnedErrorCode(command: String, errorcode: Int)` if the exit code is anything but 0.
332
-
publicfuncfinish() throws-> AsyncCommand
327
+
/// Interrupts the command by sending the SIGINT signal.
328
+
publicfuncinterrupt()
333
329
334
-
///Waits for command to finish, then returns with exit code.
335
-
publicfuncexitcode() ->Int
330
+
///Temporarily suspends a command. Call resume() to resume a suspended command.
331
+
publicfuncsuspend() ->Bool
336
332
337
-
/// Takes a closure to be called when the command has finished.
338
-
/// - Parameter handler: A closure taking this AsyncCommand as input, returning nothing.
You can process standard output and standard error, and optionally wait until it's finished and handle any errors.
345
351
346
352
If you read all of command.stderror or command.stdout it will automatically wait for the command to close its streams (and presumably finish running). You can still call `finish()` to check for errors.
347
353
354
+
`runAsyncAndPrint` does the same as `runAsync`, but prints any output directly and it's return type `PrintedAsyncCommand` doesn't have the `.stdout` and `.stderror` properties.
355
+
348
356
#### Parameters
349
357
350
-
The 3 `run` functions above take 2 different types of parameters:
358
+
The `run`* functions above take 2 different types of parameters:
351
359
352
360
##### (_ executable: String, _ args: Any ...)
353
361
@@ -385,18 +393,18 @@ If the command provided to `runAsync` could not be launched for any reason the p
385
393
386
394
```swift
387
395
let command =runAsync("cmd", "-n", 245)
388
-
//do something with command.stderror or command.stdoutCommandError
0 commit comments