在线编译器 Python

import sys import platform import subprocess import shutil print("=== ENVIRONMENT ===") print("Python:", sys.version) print("Executable:", sys.executable) print("OS:", platform.platform()) print("Architecture:", platform.machine()) print("Directory:", os.getcwd()) print("\n=== TOOLS ===") for x in ["sh", "bash", "zsh", "git", "curl", "ssh"]: print(f"{x:8} -> {shutil.which(x)}") print("\n=== ROOT ===") print(os.listdir("/")) print("\n=== SHELL ===") try: r = subprocess.run( ["sh", "-c", "uname -a; id; pwd; ls -la"], capture_output=True, text=True ) print(r.stdout) if r.stderr: print("STDERR:") print(r.stderr) except Exception as e: print("SHELL ERROR:", repr(e))
The code prints environment details, checks for common tools, lists the root directory, and runs a shell command. However, it will fail immediately because `os` is used but never imported.

- Add `import os` at the top of the file, alongside the other imports.
- After fixing the import, the code should run, but note that `os.getcwd()` and `os.listdir("/")` depend on the current working directory and permissions, so results may vary.