NDH
NDH17mo ago

Run examples on Windows

Anyone know how to run the Piping to files example on Windows? https://deno.land/manual@v1.30.3/examples/subprocess 'yes' is ignored, and I get a final error for the kill request
process.kill("SIGINT");
process.kill("SIGINT");
error: Uncaught PermissionDenied: Access is denied. (os error 5) process.kill("SIGINT");
6 Replies
ioB
ioB17mo ago
I believe this api is being deprecated so I think this example should be updated
NDH
NDH17mo ago
Will there be any instruction for this example on Windows? What is the replacement for deno.run? Any existing documentation ?
ioB
ioB17mo ago
Deno.Command is the alternative there are docs but it's unstable until next major release (1.31.0)
NDH
NDH17mo ago
Thanks <:party_deno:1035517691517218847> I've never used this help before. Can I close this?
ioB
ioB17mo ago
It just stays open but you can rename the title to make it clear you don't still need help though honestly I would avoid doing that until you have whatever you wanted to have working working
NDH
NDH17mo ago
Thanks again. For anyone else!
/**
* subprocess_piping_to_file.ts
*/

import { mergeReadableStreams } from "https://deno.land/std@0.177.0/streams/merge_readable_streams.ts";

// create the file to attach the process to
const file = await Deno.open("./process_output.txt", {
read: true,
write: true,
create: true,
});

// start the process
const process = Deno.run({
//
// changed this from ["yes"] to ["cmd", "clear"]
//
cmd: ["cmd", "clear"],
stdout: "piped",
stderr: "piped",
});

// example of combining stdout and stderr while sending to a file
const joined = mergeReadableStreams(
process.stdout.readable,
process.stderr.readable,
);

// returns a promise that resolves when the process is killed/closed
joined.pipeTo(file.writable).then(() => console.log("pipe join done"));

// manually stop process "yes" will never end on its own
setTimeout(() => {

//
// changed this from SIGINT to SIGTERM
//
process.kill("SIGTERM");
process.close()
}, 1000);
/**
* subprocess_piping_to_file.ts
*/

import { mergeReadableStreams } from "https://deno.land/std@0.177.0/streams/merge_readable_streams.ts";

// create the file to attach the process to
const file = await Deno.open("./process_output.txt", {
read: true,
write: true,
create: true,
});

// start the process
const process = Deno.run({
//
// changed this from ["yes"] to ["cmd", "clear"]
//
cmd: ["cmd", "clear"],
stdout: "piped",
stderr: "piped",
});

// example of combining stdout and stderr while sending to a file
const joined = mergeReadableStreams(
process.stdout.readable,
process.stderr.readable,
);

// returns a promise that resolves when the process is killed/closed
joined.pipeTo(file.writable).then(() => console.log("pipe join done"));

// manually stop process "yes" will never end on its own
setTimeout(() => {

//
// changed this from SIGINT to SIGTERM
//
process.kill("SIGTERM");
process.close()
}, 1000);