Hugo Garcia-Cotte commited on
Commit
418b498
1 Parent(s): 4abf8ac

Add first version of the game file

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -4,12 +4,30 @@ import subprocess
4
  # Create an input text box
5
  input_text = st.text_input('Enter some text')
6
 
7
- # Launch a subprocess and pass the input text as an argument
8
- proc = subprocess.Popen(['python', 'danse_macabre.py'], stdout=subprocess.PIPE)
9
-
10
- # Listen to the output of the subprocess and display it
11
- while True:
12
- line = proc.stdout.readline().decode('utf-8').strip()
13
- if not line:
14
- break
15
- st.write(line)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Create an input text box
5
  input_text = st.text_input('Enter some text')
6
 
7
+ def start(executable_file):
8
+ return subprocess.Popen(
9
+ executable_file,
10
+ stdin=subprocess.PIPE,
11
+ stdout=subprocess.PIPE,
12
+ stderr=subprocess.PIPE)
13
+
14
+
15
+ def read(process):
16
+ return process.stdout.readline().decode("utf-8").strip()
17
+
18
+
19
+ def write(process, message):
20
+ process.stdin.write(f"{message.strip()}\n".encode("utf-8"))
21
+ process.stdin.flush()
22
+
23
+
24
+ def terminate(process):
25
+ process.stdin.close()
26
+ process.terminate()
27
+ process.wait(timeout=0.2)
28
+
29
+
30
+ process = start("./dummy.py")
31
+ write(process, "hello dummy")
32
+ st.write(read(process))
33
+ terminate(process)