File size: 752 Bytes
158215f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
import sys

def run_code(code_string):
    """Run the provided code string directly"""
    # Create a clean globals dictionary
    globals_dict = {
        '__name__': '__main__'
    }
    
    # Execute the code
    try:
        exec(code_string, globals_dict)
        print("Code executed successfully.")
    except Exception as e:
        print(f"Error: {type(e).__name__}: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    # Get code from command line argument or stdin
    if len(sys.argv) > 1:
        # Code is provided in the argument
        code = sys.argv[1]
    else:
        # Read code from stdin
        code = sys.stdin.read()
    
    # Run the code
    run_code(code)