From ab266aee8bf4c4273850935ad988f75e5ddd22a0 Mon Sep 17 00:00:00 2001 From: "OKIDOKI\\shahz" Date: Mon, 17 Mar 2025 21:20:18 +0530 Subject: [PATCH 1/2] modified cpp.sh --- cpp.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/cpp.sh b/cpp.sh index c5387ab..1207950 100644 --- a/cpp.sh +++ b/cpp.sh @@ -15,33 +15,31 @@ 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 +else + echo "Invalid language specified! Use 'c' or 'cpp'." + exit 1 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 +# Check if input file exists +INPUT_FILE="/usr/src/app/cpp-engine/app/input.txt" +if [ -f "$INPUT_FILE" ]; then # Run the compiled program with input redirection - ./output_program < /usr/src/app/cpp-engine/app/input.txt > output.txt 2> runtime_error.txt + ./output_program < "$INPUT_FILE" > output.txt 2> runtime_error.txt else # Run the compiled program without input redirection ./output_program > output.txt 2> runtime_error.txt fi -# end + +# Check if there were any runtime errors if [ $? -ne 0 ]; then + echo -e "Runtime error!\n" cat runtime_error.txt exit 1 fi From 66f4c80e6639d0843dd15c7f427ac6dd01af0031 Mon Sep 17 00:00:00 2001 From: "OKIDOKI\\shahz" Date: Mon, 17 Mar 2025 21:22:24 +0530 Subject: [PATCH 2/2] changed js.sh file now by AETHERAI --- js.sh | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/js.sh b/js.sh index 0da7646..3281c76 100644 --- a/js.sh +++ b/js.sh @@ -1,6 +1,7 @@ #!/bin/bash # Path to the Python file to run +CODE_FILE="/usr/src/app/js-engine/app/index.js" INPUT_REQUIRED=false # Check for the flag (modify if using a different flag name) @@ -9,22 +10,39 @@ if [[ "$1" == "inputtrue" ]]; then shift # Remove the flag from the argument list fi - -CODE_FILE="/usr/src/app/js-engine/app/index.js" - - +# Execute the nodejs command if [[ $INPUT_REQUIRED == true ]]; then - - nodejs $CODE_FILE < /usr/src/app/js-engine/app/input.txt > output.txt 2> runtime_error.txt - + if nodejs $CODE_FILE < /usr/src/app/js-engine/app/input.txt > output.txt 2> runtime_error.txt; then + # Check if output.txt exists and is not empty before printing. + if [ -s output.txt ]; then + cat output.txt + else + echo "Output file is empty." + fi + else + echo "Runtime error!" + if [ -s runtime_error.txt ]; then + cat runtime_error.txt + else + echo "No runtime error message available." + fi + exit 1 + fi else - nodejs $CODE_FILE > output.txt 2> runtime_error.txt -fi - -if [ $? -ne 0 ]; then - echo "Runtime error!" - cat runtime_error.txt - exit 1 -fi - -cat output.txt + if nodejs $CODE_FILE > output.txt 2> runtime_error.txt; then + # Check if output.txt exists and is not empty before printing. + if [ -s output.txt ]; then + cat output.txt + else + echo "Output file is empty." + fi + else + echo "Runtime error!" + if [ -s runtime_error.txt ]; then + cat runtime_error.txt + else + echo "No runtime error message available." + fi + exit 1 + fi +fi \ No newline at end of file