Skip to content

[Feature Request] Option to execute script from stdin like nodejs #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dann37 opened this issue Mar 3, 2025 · 4 comments · Fixed by #947
Closed

[Feature Request] Option to execute script from stdin like nodejs #945

Dann37 opened this issue Mar 3, 2025 · 4 comments · Fixed by #947
Labels
enhancement New feature or request

Comments

@Dann37
Copy link

Dann37 commented Mar 3, 2025

Example:
echo "console.log('Hello World');" | node -

@bnoordhuis
Copy link
Contributor

That almost already works if you write it like echo 'print("hello")' | qjs /dev/stdin except for the fact that js_load_file treats fseek errors as fatal.

It tries to be clever and first size the file so it knows how much memory to allocate upfront but it could just read the file in blocks and allocate on the go.

@bnoordhuis bnoordhuis added the enhancement New feature or request label Mar 3, 2025
@saghul
Copy link
Contributor

saghul commented Mar 3, 2025

We are this close to moving all that to cli.js at this point, aren't we? 😅

bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Mar 3, 2025
Replace js_load_file with something that doesn't choke on special files
and don't call realpath(3) on /dev files because that doesn't work.

Fixes: quickjs-ng#945
@bnoordhuis
Copy link
Contributor

Quite possibly, but in the interim #947 is an easy fix :-)

@Dann37
Copy link
Author

Dann37 commented Mar 4, 2025

Works great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants