vwkd
vwkd2y ago

Empty output in Deno.Command

I’m trying to run the command git log —grep='.' from Deno. However, it always returns an empty output. If I delete the grep option it returns it fine. Running the same command from the CLI returns all commits. It’s weird because other “similarly looking options” seem to work fine for example —format.
const command = new Deno.Command("git", { args: [
"log",
// grep seems make problems
"--grep='.'",
// "--format='%h %s'",
]});
const { code, stdout, stderr } = await command.output();
console.log(code)
console.log(new TextDecoder().decode(stdout))
console.log(new TextDecoder().decode(stderr))
const command = new Deno.Command("git", { args: [
"log",
// grep seems make problems
"--grep='.'",
// "--format='%h %s'",
]});
const { code, stdout, stderr } = await command.output();
console.log(code)
console.log(new TextDecoder().decode(stdout))
console.log(new TextDecoder().decode(stderr))
2 Replies
vwkd
vwkdOP2y ago
Okay, without the single quotes like "—grep=." it works. However, this leaves the question how to use it with more patterns like containing spaces? Okay, separating the value to the —grep option into a separate argument like … "—grep", ".", … fixed it. Funnily, this does not work with the similarly looking —format argument.
Hexagon
Hexagon2y ago
@vwkd Have you tried "--format", "%h %s"? Since it is an array of arguments, you shouldn't need to enclose arguments with space in quotes - as long as you don't do anything funky, like pass a command as an argument to a command.