OILS / pea / testdata / sig_err.py View on Github | oilshell.org

65 lines, 42 significant
1#!/usr/bin/env python2
2"""
3osh_eval.py
4"""
5from __future__ import print_function
6
7import sys
8
9from asdl import runtime
10from core import error
11from core import shell
12from core.pyerror import log
13from core import pyos
14from core import pyutil
15from core.pyutil import stderr_line
16from frontend import args
17from frontend import flag_def # side effect: flags are defined!
18unused2 = flag_def
19
20from typing import List
21
22
23def 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
64if __name__ == '__main__':
65 sys.exit(main(sys.argv))