AtharvaThakur/Insights
0
1import subprocess2def run_script():3 try:4 # Run the script5 result = subprocess.run(6 ['python', 'code.py'],7 capture_output=True, # Capture stdout and stderr8 text=True # Get the output as string9 )10 11 # Check the return code to determine if an error occurred12 if result.returncode != 0:13 print("Script failed with error:")14 print(result.stderr)15 return 1,result.stderr16 else:17 print("Script completed successfully:")18 print(result.stdout)19 return 0,result.stdout20 except Exception as e:21 print(f"Failed to run the script: {e}")22 return 2,e