1 | #!/usr/bin/env python2
|
2 | """
|
3 | osh_eval.py
|
4 | """
|
5 | from __future__ import print_function
|
6 |
|
7 | import sys
|
8 |
|
9 | from asdl import runtime
|
10 | from core import error
|
11 | from core import shell
|
12 | from core.pyerror import log
|
13 | from core import pyos
|
14 | from core import pyutil
|
15 | from core.pyutil import stderr_line
|
16 | from frontend import args
|
17 | from frontend import flag_def # side effect: flags are defined!
|
18 | unused2 = flag_def
|
19 |
|
20 | from typing import List
|
21 |
|
22 |
|
23 | def main(argv):
|
24 | # type: (List[str_SYNTAX_ERROR) -> int
|
25 | loader = pyutil.GetResourceLoader()
|
26 | login_shell = False
|
27 |
|
28 | environ = pyos.Environ()
|
29 |
|
30 | arg_r = args.Reader(argv, spids=[runtime.NO_SPID] * len(argv))
|
31 |
|
32 | try:
|
33 | status = shell.Main('osh', arg_r, environ, login_shell, loader, None)
|
34 | return status
|
35 | except error.Usage as e:
|
36 | #builtin.Help(['oil-usage'], util.GetResourceLoader())
|
37 | log('oil: %s', e.msg)
|
38 | return 2
|
39 | except RuntimeError as e:
|
40 | if 0:
|
41 | import traceback
|
42 | traceback.print_exc()
|
43 | # NOTE: The Python interpreter can cause this, e.g. on stack overflow.
|
44 | # f() { f; }; f will cause this
|
45 | msg = e.message # type: str
|
46 | stderr_line('osh fatal error: %s', msg)
|
47 | return 1
|
48 |
|
49 | # Note: This doesn't happen in C++.
|
50 | except KeyboardInterrupt:
|
51 | print('')
|
52 | return 130 # 128 + 2
|
53 |
|
54 | except (IOError, OSError) as e:
|
55 | if 0:
|
56 | import traceback
|
57 | traceback.print_exc()
|
58 |
|
59 | # test this with prlimit --nproc=1 --pid=$$
|
60 | stderr_line('osh I/O error: %s', pyutil.strerror(e))
|
61 | return 2 # dash gives status 2
|
62 |
|
63 |
|
64 | if __name__ == '__main__':
|
65 | sys.exit(main(sys.argv))
|