anuragbb commited on
Commit
ace688c
·
verified ·
1 Parent(s): 6ed9eed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -316,31 +316,35 @@ def execute_python(code):
316
  # In[35]:
317
 
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  def execute_cpp(code):
320
- write_output(code)
321
  try:
322
- # Windows compilation and execution commands
323
- compile_cmd = ["g++", "-O3", "-std=c++17", "-o", "optimized.exe", "optimized.cpp"]
324
- compile_result = subprocess.run(compile_cmd, check=True, text=True, capture_output=True)
325
- run_cmd = ["optimized.exe"]
326
- run_result = subprocess.run(run_cmd, check=True, text=True, capture_output=True)
327
- return run_result.stdout
 
 
 
 
328
  except subprocess.CalledProcessError as e:
329
- return f"An error occurred:\n{e.stderr}"
330
 
331
 
332
- # def execute_cpp():
333
- # try:
334
- # print("Compiling C++ code...")
335
- # # Adjust the output filename to 'optimized' for Linux
336
- # subprocess.run(['g++', '-O3', '-std=c++17', '-o', 'optimized', 'optimized.cpp'], check=True)
337
- # print("Running optimized executable...")
338
- # # Execute the Linux-compatible executable
339
- # result = subprocess.run(['./optimized'], check=True, text=True, capture_output=True)
340
- # return result.stdout
341
- # except subprocess.CalledProcessError as e:
342
- # return f"Error during compilation or execution: {e.stderr}"
343
-
344
 
345
  # In[51]:
346
 
 
316
  # In[35]:
317
 
318
 
319
+ # def execute_cpp(code):
320
+ # write_output(code)
321
+ # try:
322
+ # # Windows compilation and execution commands
323
+ # compile_cmd = ["g++", "-O3", "-std=c++17", "-o", "optimized.exe", "optimized.cpp"]
324
+ # compile_result = subprocess.run(compile_cmd, check=True, text=True, capture_output=True)
325
+ # run_cmd = ["optimized.exe"]
326
+ # run_result = subprocess.run(run_cmd, check=True, text=True, capture_output=True)
327
+ # return run_result.stdout
328
+ # except subprocess.CalledProcessError as e:
329
+ # return f"An error occurred:\n{e.stderr}"
330
+
331
+
332
  def execute_cpp(code):
 
333
  try:
334
+ print("Compiling C++ code...")
335
+ compile_result = subprocess.run(
336
+ ['g++', '-O3', '-std=c++17', '-o', 'optimized', 'optimized.cpp'],
337
+ check=True, text=True, capture_output=True
338
+ )
339
+ print("Compilation output:", compile_result.stdout)
340
+ print("Running optimized executable...")
341
+ subprocess.run(['chmod', '+x', 'optimized'], check=True)
342
+ result = subprocess.run(['./optimized'], check=True, text=True, capture_output=True)
343
+ return result.stdout
344
  except subprocess.CalledProcessError as e:
345
+ return f"Error during compilation or execution: {e.stderr}"
346
 
347
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
  # In[51]:
350