summaryrefslogtreecommitdiff
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-06-04 23:42:45 +0100
committerDamien George <damien.p.george@gmail.com>2015-06-04 23:42:45 +0100
commit031278f661e5d285c56359e355a96161bf6e1a9f (patch)
tree28bbc709418b0e81b941f8ad014ed2a5aab86165 /unix
parent9724a0538b82109992bfe9322008eab7f62064b7 (diff)
unix: Allow to cat a script into stdin from the command line.
See issue #1306.
Diffstat (limited to 'unix')
-rw-r--r--unix/main.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/unix/main.c b/unix/main.c
index 2bdb39efa..bb5a2b582 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <unistd.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -447,9 +448,14 @@ int main(int argc, char **argv) {
}
if (ret == NOTHING_EXECUTED) {
- prompt_read_history();
- ret = do_repl();
- prompt_write_history();
+ if (isatty(0)) {
+ prompt_read_history();
+ ret = do_repl();
+ prompt_write_history();
+ } else {
+ mp_lexer_t *lex = mp_lexer_new_from_fd(MP_QSTR__lt_stdin_gt_, 0, false);
+ ret = execute_from_lexer(lex, MP_PARSE_FILE_INPUT, false);
+ }
}
#if MICROPY_PY_MICROPYTHON_MEM_INFO