FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programmingWithPythonCode/_scripts_/pythonIgnoreErrors.sh at main · mlecjm/programmingWithPythonCode · GitHub
mlecjm
programmingWithPythonCode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programmingWithPythonCode
/
_scripts_
/
pythonIgnoreErrors.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
25 lines (19 loc) · 1.01 KB
Breadcrumbs
programmingWithPythonCode
/
_scripts_
/
pythonIgnoreErrors.sh
Copy path
File metadata and controls
executable file
·
25 lines (19 loc) · 1.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!
/bin/bash -
#
This program executes python but ignores the errors.
#
Argument $1: the directory in which the command should run
#
Argument $2: the file to run
#
We enforce strict error handling, i.e., fail on any unexpected error.
set
-o pipefail
#
trace errors through pipes
set
-o errtrace
#
trace errors through commands and functions
set
-o nounset
#
exit if encountering an uninitialized variable
set
-o errexit
#
exit if any statement returns a non-0 return value
cd
"
$1
"
#
Enter the folder inside of which we should run the program.
#
Switch of "exit-on-error", run the program, then switch it back on.
set
+o errexit
#
Turn off exit-on-error.
python3
$2
2>&1
#
Run the program
exitCode=
"
$?
"
#
Store exit code of program in variable exitCode.
set
-o errexit
#
Turn exit-on-error back on.
#
Convert exit code to success or failure string.
[
"
$exitCode
"
-eq
0 ]
&&
exitCodeStr=
"
succeeded
"
||
exitCodeStr=
"
failed
"
#
Finally, we print the result string.
echo
"
# 'python3
$2
'
$exitCodeStr
with exit code
$exitCode
.
"
Back
|
FazBrowse Home
|
New Git URL