Migrating from Deno.run to Deno.command, how to readLines?
At the moment I have this:
How would I now do this if using
Deno.Command
? I'm currently spawning a long running subprocess that doesn't exit on it's own, so simply running the command, and using outputSync()
probably isnt an option11 Replies
To migrate from
Deno.run
to Deno.Command
and use readLines
with the new API, you'll need to adjust your code to work with the Deno.Command
class and its method for spawning a subprocess. The Deno.Command
class provides a spawn
method that returns a Deno.Process
object, which you can use to interact with the subprocess's input and output streams.
Here's how you can use Deno.Command
to spawn a long-running subprocess and read lines from its standard error stream:
In this example, replace "your-command"
and ["your", "args", "here"]
with the actual command and arguments you want to run. The readLines
function is used to asynchronously iterate over the lines of the subprocess's standard error stream.
Remember that since the subprocess is long-running and doesn't exit on its own, you'll need to manage the lifecycle of the subprocess yourself. This includes potentially killing the subprocess when it's no longer needed or handling any cleanup logic.
The documentation mentions that if you want to communicate with a started subprocess, you must use the "piped" option for stdin
, stdout
, and stderr
as needed. This allows you to read from or write to the subprocess's streams.
If you encounter any issues with the readLines
function or the Deno.Command
class, please make sure you are using the latest version of Deno andrefer to the official Deno documentation for the most up-to-date information and examples. 🦕
Helpful Links:
Subprocesses: Collecting Output - Deno by Example
Deno 1.21 Release Notes
Subprocesses: Spawning - Deno by Example
Deno 1.x to 2.x Migration Guide | Deno Docs
Creating a Subprocess | Deno Docs
Deno 1.29: Custom npm registry support
Log Deno.command process output - Deno
Creating a Subprocess - Deno Docs
hey long time no see!
Hey 🙂
Whats this "jsr" import syntax?
Also seems to work perfectly 🙂
JSR: the JavaScript Registry
JSR is the open-source package registry for modern JavaScript. JSR natively supports TypeScript, and works with all JS runtimes and package managers.
I am VERY behind, will give it a read
does this replace deno.land/std and deno.land/x/?
yea, at some point we will make /x/ read-only, and expecting people to rather use JSR
yep, havent seen you around in a long time
Its probs been like a year or two or something lol, wanna get back into hobby coding a bit but im so behind on deno lol, everything i knew before is probably lost in time now xD
Don’t suppose you’d know the reason for why a test file may hang, there’s no errors or leaking ops message, it just hangs on
<test step name> … ok (4s)
,
I’d assume there’s a promise not being resolved but wouldn’t deno throw an error message for this?
It’s still using sub processes and is only an issue on windowsI’d assume there’s a promise not being resolved but wouldn’t deno throw an error message for this?usually yes 🤔 could you share it?
probs quite a complex case cause its sinco, the one that runs chrome as a subprocess so unfortunately the test cases aren't helpful cause we'd need to dig down into the src code, i can still share regardless, bear with
i'm still going thru it trying to see if there's any thing i haven't resolved
test file: https://github.com/drashland/sinco/blob/fix-tests/tests/unit/client_test.ts#L7-L54, sometimes works when ran, sometimes hangs
GitHub
sinco/tests/unit/client_test.ts at fix-tests · drashland/sinco
Browser Automation and Testing Tool for Deno, written in full TypeScript - drashland/sinco