anuragbb commited on
Commit
ce86e34
·
verified ·
1 Parent(s): f1e2bf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -316,17 +316,30 @@ 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
  # In[51]:
 
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]: