1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix: default to "inherit" for Deno.Command#spawn()'s stdout & stderr (#17025)

This commit is contained in:
Leo Kettmeir 2022-12-13 05:12:19 +01:00 committed by GitHub
parent 8972ebc9cc
commit a2ba573e77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View file

@ -91,6 +91,7 @@ Deno.test(
"await Deno.stdout.write(new TextEncoder().encode('hello'))",
],
stderr: "null",
stdout: "piped",
});
const child = command.spawn();
@ -124,6 +125,7 @@ Deno.test(
"await Deno.stderr.write(new TextEncoder().encode('hello'))",
],
stdout: "null",
stderr: "piped",
});
const child = command.spawn();
@ -163,6 +165,8 @@ Deno.test(
"eval",
"Deno.stderr.write(new TextEncoder().encode('error\\n')); Deno.stdout.write(new TextEncoder().encode('output\\n'));",
],
stdout: "piped",
stderr: "piped",
});
const child = command.spawn();
await child.stdout.pipeTo(file.writable, {

View file

@ -151,6 +151,8 @@ function runFlockTestProcess(opts: { exclusive: boolean; sync: boolean }) {
const process = new Deno.Command(Deno.execPath(), {
args: ["eval", "--unstable", scriptText],
stdin: "piped",
stdout: "piped",
stderr: "null",
}).spawn();
const waitSignal = async () => {

View file

@ -1383,6 +1383,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1430,7 +1431,11 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const proc = new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).spawn();
const status = await proc.status;
assert(status.success);
const stdout = proc.stdout
@ -1488,6 +1493,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout).toLocaleLowerCase();
@ -1543,6 +1549,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1595,6 +1602,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1651,6 +1659,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1709,6 +1718,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1767,6 +1777,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1822,6 +1833,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1883,6 +1895,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -1939,7 +1952,11 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const proc = new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).spawn();
const status = await proc.status;
assert(status.success);
const stdout = proc.stdout
@ -2007,6 +2024,7 @@ Deno.test({
const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).output();
assert(success);
const output = decoder.decode(stdout);
@ -2569,7 +2587,11 @@ Deno.test({
"Accept-Encoding: gzip, deflate, br",
"--no-buffer",
];
const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const proc = new Deno.Command("curl", {
args,
stderr: "null",
stdout: "piped",
}).spawn();
const stdout = proc.stdout
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new TextDecoderStream());

View file

@ -1456,11 +1456,13 @@ declare namespace Deno {
stdin?: "piped" | "inherit" | "null";
/** How `stdout` of the spawned process should be handled.
*
* Defaults to `"piped"`. */
* Defaults to `"piped"` for `output` & `outputSync`,
* and `"inherit"` for `spawn`. */
stdout?: "piped" | "inherit" | "null";
/** How `stderr` of the spawned process should be handled.
*
* Defaults to "piped". */
* Defaults to "piped" for `output` & `outputSync`,
* and `"inherit"` for `spawn`. */
stderr?: "piped" | "inherit" | "null";
/** Skips quoting and escaping of the arguments on windows. This option

View file

@ -307,7 +307,12 @@
}
spawn() {
return spawnChild(this.#command, this.#options);
const options = {
...(this.#options ?? {}),
stdout: this.#options?.stdout ?? "inherit",
stderr: this.#options?.stderr ?? "inherit",
};
return spawnChild(this.#command, options);
}
};
}