diff options
author | Chris Knight <cknight1234@gmail.com> | 2020-09-12 13:03:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-12 08:03:18 -0400 |
commit | 95db3247485b2d1ed553c98e2231379e58a0ace2 (patch) | |
tree | c6f5153101d77d2ce9342ea76fc69815ec51ccd8 /docs/examples/subprocess.md | |
parent | 10fbfcbc79eb50cb7669b4aaf67f957d97d8d93b (diff) |
doc: improve Examples (#7428)
Diffstat (limited to 'docs/examples/subprocess.md')
-rw-r--r-- | docs/examples/subprocess.md | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/docs/examples/subprocess.md b/docs/examples/subprocess.md index 72a3bc862..fad6c71bf 100644 --- a/docs/examples/subprocess.md +++ b/docs/examples/subprocess.md @@ -1,10 +1,25 @@ -## Run subprocess +# Creating a subprocess -[API Reference](https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.run) +## Concepts -Example: +- Deno is capable of spawning a subprocess via + [Deno.run](https://doc.deno.land/builtin/stable#Deno.run) +- `--allow-run` permission is required to spawn a subprocess +- Spawned subprocesses do not run in a security sandbox +- Communicate with the subprocess via the + [stdin](https://doc.deno.land/builtin/stable#Deno.stdin), + [stdout](https://doc.deno.land/builtin/stable#Deno.stdout) and + [stderr](https://doc.deno.land/builtin/stable#Deno.stderr) streams + +## Simple example + +This example is the equivalent of running `'echo hello'` from the command line. ```ts +/** + * subprocess_simple.ts + */ + // create subprocess const p = Deno.run({ cmd: ["echo", "hello"], @@ -21,16 +36,22 @@ $ deno run --allow-run ./subprocess_simple.ts hello ``` -Here a function is assigned to `window.onload`. This function is called after -the main script is loaded. This is the same as -[onload](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload) -of the browsers, and it can be used as the main entrypoint. +## Security + +The `--allow-run` permission is required for creation of a subprocess. Be aware +that subprocesses are not run in a Deno sandbox and therefore have the same +permissions as if you were to run the command from the command line yourself. + +## Communicating with subprocesses -By default when you use `Deno.run()` subprocess inherits `stdin`, `stdout` and -`stderr` of parent process. If you want to communicate with started subprocess -you can use `"piped"` option. +By default when you use `Deno.run()` the subprocess inherits `stdin`, `stdout` +and `stderr` of the parent process. If you want to communicate with started +subprocess you can use `"piped"` option. ```ts +/** + * subprocess.ts + */ const fileNames = Deno.args; const p = Deno.run({ |