Closed char8x closed 5 months ago
So from my basic understanding (just going to write this out to ensure I'm on the right page) this isn't an sh feature and is something found in other shells like bash. It requires creating a pipe containing the string's contents and passing the file descriptor of that pipe as an argument to the diff
subprocess. For this to work in dax there would need to be a way in Deno of creating named pipes and then providing those to subprocesses as arguments (it's something that's been discussed in the past and I think we could do it).
Looking at diff
, it seems like there isn't a way to just provide it two strings as arguments. This is the best I can do in this scenario for the time being, which is slightly unfortunate:
async function diff(a: string, b: string) {
async function makeTempFile() {
const filePath = await Deno.makeTempFile();
return $.path(filePath);
}
const [temp1, temp2] = await Promise.all([makeTempFile(), makeTempFile()]);
try {
await Promise.all([temp1.writeText(a), temp2.writeText(b)]);
await $`diff ${temp1} ${temp2}`;
} finally {
await Promise.all([temp1.remove(), temp2.remove()]);
}
}
const a = "12345"
const b = "23456"
await diff(a, b);
Thank you for sharing your understanding. You are correct that this feature isn't native to sh
and is more commonly found in shells like bash
. I appreciate your insight into the potential solution for Dax, and I agree that having the capability to create named pipes in Deno and passing them as arguments to subprocesses would be a valuable addition.
I was wondering if it would be possible to instead set fds
ourselves. For example, imagemagick lets you run something like convert fd:3 fd:4
to take data from pipe 3 and 4 to use. Here's an example of it for a different project in node.
Is there any way to make the following code execute successfully
Example 1
Output
Example 2
Output
Env
dax@0.31.1 deno 1.33.2