dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
969 stars 33 forks source link

output redirection in command throws "Async commands are not supported" error #179

Closed wvh closed 5 months ago

wvh commented 10 months ago

Hello!

This command:

await $`echo 1 && echo stderr >&2`;

throws this error:

error: Uncaught (in promise) Error: Async commands are not supported. Run a command concurrently in the JS code instead.
      throw new Error("Async commands are not supported. Run a command concurrently in the JS code instead.");

This is not an async command, I guess the ampersand is misinterpreted as a background task operator?

Shouldn't it be possible to pass through the redirection to the shell and allow the command to write to STDERR this way? At least writing a simple shell script one-liner that writes to STDERR properly catches the output, so this is just about the initial command set-up.

Thanks for your time!

sigmaSd commented 10 months ago

dax doesn't support redirection and >&2 syntax, you'll have to use .stdout("piped").stderr("piped") and extract the result and merge it manually.

pomdtr commented 9 months ago

It would be nice to just be able to do:

$`echo 1`.stdout(Deno.stderr)
dsherret commented 5 months ago

@pomdtr that's possible nowadays.

pomdtr commented 5 months ago

I can imagine, I created the PR (https://github.com/dsherret/dax/pull/184).

thanks for merging it btw !

dsherret commented 5 months ago

Hah! Thanks again 😄

dsherret commented 5 months ago

This is fixed now in the latest release:

const result = await $`echo 1 && echo stderr >&2`.stdout("piped").stderr("piped");
console.log("stdout", result.stdout); // stdout 1\n
console.log("stderr", result.stderr); // stderr stderr\n