Migrating from Deno.run to Deno.command, how to readLines?

At the moment I have this:
const command = new Deno.command('...');
for await (const line of readLines(command.stderr!)) {
// ...
break;
}

// .. Continue using sun process
const command = new Deno.command('...');
for await (const line of readLines(command.stderr!)) {
// ...
break;
}

// .. Continue using sun process
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 option
Deno AI Helper
Deno AI Helper•20d ago
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:
import { readLines } from "https://deno.land/std/io/mod.ts";

const command = new Deno.Command("your-command", {
args: ["your", "args", "here"],
stderr: "piped", // Ensure that stderr is piped
});

const process = command.spawn();

// Assuming you want to read from stderr
for await (const line of readLines(process.stderr)) {
console.log(line);
// ... your logic here
}

// Continue using the subprocess
// ...
import { readLines } from "https://deno.land/std/io/mod.ts";

const command = new Deno.Command("your-command", {
args: ["your", "args", "here"],
stderr: "piped", // Ensure that stderr is piped
});

const process = command.spawn();

// Assuming you want to read from stderr
for await (const line of readLines(process.stderr)) {
console.log(line);
// ... your logic here
}

// Continue using the subprocess
// ...
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 and
crowlKats
crowlKats•20d ago
hey long time no see!
import { TextLineStream } from "jsr:@std/streams";

const command = new Deno.command('...');
const child = command.spawn();
for await (const line of command.stderr.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream())) {}
import { TextLineStream } from "jsr:@std/streams";

const command = new Deno.command('...');
const child = command.spawn();
for await (const line of command.stderr.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream())) {}
Ed, Edd n Eddy
Ed, Edd n Eddy•20d ago
Hey 🙂 Whats this "jsr" import syntax? Also seems to work perfectly 🙂
crowlKats
crowlKats•20d ago
its for https://jsr.io/ !
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.
Ed, Edd n Eddy
Ed, Edd n Eddy•20d ago
I am VERY behind, will give it a read does this replace deno.land/std and deno.land/x/?
crowlKats
crowlKats•20d ago
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
Ed, Edd n Eddy
Ed, Edd n Eddy•20d ago
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 windows
crowlKats
crowlKats•20d ago
I’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?
Ed, Edd n Eddy
Ed, Edd n Eddy•20d ago
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
Ed, Edd n Eddy
Ed, Edd n Eddy•20d ago
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
More Posts
How to abstract tests to allow running different functions against the same test suite?I've set up two suites of tests like this: https://github.com/gustwindjs/gustwind/tree/develop/htmliFresh tabler icon classHello I want to use the fresh tabler icon lib without using the npm version like this: ```ts { "iRedirection in Testing is Always Valued FalseThis is my first test in full stack framework, especially for Fresh. I'm not sure why the `redirecteNeovim setup with LSP formatting & lintinghello, I am trying to set up the fmt & linting using nvim-lspconfig with neovim Anyone know how i sblock js with #[op2] fn without blocking rust threadI'm using deno_core and I'm looking for a way to block the js main thread without using a sync functConnect to managed databases from "INSIDE" of Deno DeployHi I am trying to connect to a managed database from INSIDE another application in deno Deploy. But something wrong with deno i thinkidk but sh1t wont work?Buffer.from equivalent in deno?on node.js ```js const signerPvtKey = Buffer.from( // process.env.PVT_KEY PVT_KEY, "he'Deno.exit' is not allowed in this context.Locally I can do in a nest project npm run build deno run -A .enviroment/deploy.ts and it works coWASM version of SWC.RC errors only in debug modeNOTE: This is a bare bones example just to illustrate the problem: we aren't transpiling anything juWith Deno.serveHttp marked as deprecated is there a way to run an HTTP server off of a Deno.Conn?I have a bit of weird use-case where I want to start a listener, accept the first TCP connection (anIs this correct for Javascript?https://github.com/tc39/proposal-change-array-by-copy This is my opinion about it: This kind of proDenoLS interfering with TsServer in neovimAny way i could fix this?Finalization not workingI can't get the gc to run a destructor.. At first I thought that I'm making some kind of mistake herdeno inside of a docker containerDespite installing it and confirming it inside I can't run deno in this container. Any idea why?Packaging deno packages to be used in an air-gapped environmentI work in an air-gapped environment, where I, as a user have no access to the internet. For developno-slow-types should not trigger on 'as const' objectsI get an on-slow-types error for an `as const` object, but shouldn't this be inferred? https://githFsWatcher.close() error : BadResourceHi community 🙂 I have an error when i try to close watcher after it throw remove event on directoryCron BackoffSchedule 502When testing the sample code from the Deno Deploy docs in the Deno playgroud, I'm getting a 502 bad i need help why isnt C:\Users\ollie\.deno\bin\deno.exe showing up?for some reason, C:\Users\ollie\.deno\bin\deno.exe isnt showing up i just made deno and i cant find