-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp.sh
More file actions
49 lines (42 loc) · 1.24 KB
/
Copy pathcpp.sh
File metadata and controls
49 lines (42 loc) · 1.24 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Path to the code file to compile
# /usr/src/app/cpp-engine/app/main
if [ -z "$1" ]; then
echo "No language specified! Use 'c' or 'cpp'."
exit 1
fi
FILE_EXTENSION="$1"
CODE_FILE="/usr/src/app/cpp-engine/app/main.${FILE_EXTENSION}"
if [ "$FILE_EXTENSION" == "c" ]; then
clang -o output_program "$CODE_FILE" 2> compile_error.txt
elif [ "$FILE_EXTENSION" == "cpp" ]; then
clang++ -o output_program "$CODE_FILE" 2> compile_error.txt
fi
# Check if there were any compilation errors
if [ $? -ne 0 ]; then
echo -e "Compilation failed!\n"
cat compile_error.txt
exit 1
fi
# Run the compiled program and capture runtime errors
./output_program > output.txt 2> runtime_error.txt
# Check if there were any runtime errors
if [ $? -ne 0 ]; then
echo -e "Runtime error!\n"
cat runtime_error.txt
exit 1
fi
# start
if [ -f "/usr/src/app/cpp-engine/app/input.txt" ]; then
# Run the compiled program with input redirection
./output_program < /usr/src/app/cpp-engine/app/input.txt > output.txt 2> runtime_error.txt
else
# Run the compiled program without input redirection
./output_program > output.txt 2> runtime_error.txt
fi
# end
if [ $? -ne 0 ]; then
cat runtime_error.txt
exit 1
fi
cat output.txt