-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect between stderr and stdout in Deno.Command
#2750
Comments
This would be very convenient when a program outputs on stdout when it should be on Deno's stderr. This would be especially nice if it streamed.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Thanks to some help from crowlKats in the discord, I created a Sprinter to make subprocesses more convenient. If people find it useful I'll upgrade it over time. import { run, Out, Stdout, Stderr, Overwrite, AppendTo, Timeout } from "https://deno.land/x/[email protected]/index.js"
// yes &> my_log.txt
await run("yes", Out(Overwrite("my_log.txt")))
// yes &>> my_log.txt
await run("yes", Out(AppendTo("my_log.txt")))
// yes 1>> my_log.txt
await run("yes", Stdout(AppendTo("my_log.txt")))
// yes 1>my_log.txt 2>>my_error_log.txt
await run("yes", Stdout(Overwrite("my_log.txt")), Stderr(AppendTo("my_error_log.txt")))
// using an already-open file
const file = await Deno.open("./my_log.txt", { read: false, write: true, create: true, })
await run("yes", Out(AppendTo(file)))
// with a timeout
await run("yes", Out(AppendTo(file)), Timeout({ gentlyBy: 100, waitBeforeUsingForce: 500})) There's more, like piping multiple files as input and multiple files as output, but those above should cover the basic use-cases. |
Deno.Command
Ref #1828 (comment)
Rather than adding
Process::combinedOutput()
, I propose modelling2>&1
inRunOptions
.Ref https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module
->
The text was updated successfully, but these errors were encountered: