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'))", "await Deno.stdout.write(new TextEncoder().encode('hello'))",
], ],
stderr: "null", stderr: "null",
stdout: "piped",
}); });
const child = command.spawn(); const child = command.spawn();
@ -124,6 +125,7 @@ Deno.test(
"await Deno.stderr.write(new TextEncoder().encode('hello'))", "await Deno.stderr.write(new TextEncoder().encode('hello'))",
], ],
stdout: "null", stdout: "null",
stderr: "piped",
}); });
const child = command.spawn(); const child = command.spawn();
@ -163,6 +165,8 @@ Deno.test(
"eval", "eval",
"Deno.stderr.write(new TextEncoder().encode('error\\n')); Deno.stdout.write(new TextEncoder().encode('output\\n'));", "Deno.stderr.write(new TextEncoder().encode('error\\n')); Deno.stdout.write(new TextEncoder().encode('output\\n'));",
], ],
stdout: "piped",
stderr: "piped",
}); });
const child = command.spawn(); const child = command.spawn();
await child.stdout.pipeTo(file.writable, { 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(), { const process = new Deno.Command(Deno.execPath(), {
args: ["eval", "--unstable", scriptText], args: ["eval", "--unstable", scriptText],
stdin: "piped", stdin: "piped",
stdout: "piped",
stderr: "null",
}).spawn(); }).spawn();
const waitSignal = async () => { const waitSignal = async () => {

View file

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

View file

@ -1456,11 +1456,13 @@ declare namespace Deno {
stdin?: "piped" | "inherit" | "null"; stdin?: "piped" | "inherit" | "null";
/** How `stdout` of the spawned process should be handled. /** 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"; stdout?: "piped" | "inherit" | "null";
/** How `stderr` of the spawned process should be handled. /** 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"; stderr?: "piped" | "inherit" | "null";
/** Skips quoting and escaping of the arguments on windows. This option /** Skips quoting and escaping of the arguments on windows. This option

View file

@ -307,7 +307,12 @@
} }
spawn() { 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);
} }
}; };
} }