Luis-Filipe commited on
Commit
812f824
·
verified ·
1 Parent(s): 3ea34ba

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -16,25 +16,27 @@ def run_pcbasic_code(code, timeout=60):
16
  f.write(code)
17
 
18
  try:
19
- process = subprocess.run(
20
  [
21
  "pcbasic",
22
  f"--run={code_path}",
23
  "--interface=sdl2",
24
  "--video=SDL2",
25
- "--output", img_path
26
  ],
27
- timeout=timeout,
28
- capture_output=True
29
  )
30
 
31
- text_output = process.stdout.decode('utf-8', errors='replace')
 
 
32
  if os.path.exists(img_path):
33
  img = Image.open(img_path)
34
  return text_output, img
35
  else:
36
  return text_output, None
37
  except subprocess.TimeoutExpired:
 
38
  return "Erro: Tempo limite de execução excedido", None
39
  except Exception as e:
40
  return f"Erro: {str(e)}", None
 
16
  f.write(code)
17
 
18
  try:
19
+ process = subprocess.Popen(
20
  [
21
  "pcbasic",
22
  f"--run={code_path}",
23
  "--interface=sdl2",
24
  "--video=SDL2",
 
25
  ],
26
+ stdout=subprocess.PIPE,
27
+ stderr=subprocess.PIPE
28
  )
29
 
30
+ text_output, _ = process.communicate(timeout=timeout)
31
+ text_output = text_output.decode('utf-8', errors='replace')
32
+
33
  if os.path.exists(img_path):
34
  img = Image.open(img_path)
35
  return text_output, img
36
  else:
37
  return text_output, None
38
  except subprocess.TimeoutExpired:
39
+ process.kill()
40
  return "Erro: Tempo limite de execução excedido", None
41
  except Exception as e:
42
  return f"Erro: {str(e)}", None