8000 unix: difference to CPython when catting script into stdin · Issue #1306 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

unix: difference to CPython when catting script into stdin #1306

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
dpgeorge opened this issue Jun 3, 2015 · 7 comments
Closed

unix: difference to CPython when catting script into stdin #1306

dpgeorge opened this issue Jun 3, 2015 · 7 comments

Comments

@dpgeorge
Copy link
Member
dpgeorge commented Jun 3, 2015

In CPython you can cat the script into stdin:

cat 'print(123)\nprint(456)' | python

This works as expected. In uPy if you do this then it enters the REPL and the stdin data is interpreted at the REPL.

I think we should follow CPython here. It's more unixy.

@pfalcon
Copy link
Contributor
pfalcon commented Jun 3, 2015

Sounds good, isatty(), etc.

@dpgeorge
Copy link
Member Author
dpgeorge commented Jun 3, 2015

It'll break all tests in tests/cmdline... but I'm prepared to deal with that :)

@dpgeorge
Copy link
Member Author
dpgeorge commented Jun 3, 2015

Ok, it's pretty trivial to implement this using the following:

if (!isatty(0)) {
    do_file("/dev/stdin");
}

But that probably won't work on windows... does windows have isatty? I'm pretty sure it doesn't have /dev/stdin :)

Other option that will work on windows is to make a new wrapper for the lexer to init a file from a file descriptor. But that adds bulk. @stinos any suggestions?

@stinos
Copy link
Contributor
stinos commented Jun 4, 2015

Windows has isatty() and it works fine as far as I can tell.
I see no other way to read from stdin then to, well, just read from stdin - through it's descriptor that is.
So if you don't want to add a lexer_from_fd or so, I don't have any other suggestion than to make open() for the win port to return the stdin descriptor when passed the /dev/stdin string instead of trying to actually open from the filesystem.

@stinos stinos mentioned this issue Jun 4, 2015
@dhylands
Copy link
Contributor
dhylands commented Jun 4, 2015

I would be inclined to make lexer_from_fd and have it also take a filename argument for error reporting purposes. Then you can use stdin or pipes or whatever.

Make the existing lexer function open the file and pass the filename in. Hardly adds any extra code.

@dpgeorge
Copy link
Member Author
dpgeorge commented Jun 4, 2015

I agree with @dhylands to provide a way to open directly a file descriptor.

@dpgeorge
Copy link
Member Author
dpgeorge commented Jun 4, 2015

Implemented.

@dpgeorge dpgeorge closed this as completed Jun 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0