goingyt commited on
Commit
215c411
Β·
verified Β·
1 Parent(s): 1ecfe75

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +11 -6
app/main.py CHANGED
@@ -14,16 +14,21 @@ def index():
14
  @socketio.on('input', namespace='/terminal')
15
  def handle_input(data):
16
  command = data['command']
17
- print(f"Received command: {command}") # Debugging log
18
  result = execute_command(command)
19
  emit('output', {'output': result})
20
 
21
  def execute_command(command):
22
- result = subprocess.run(['docker', 'exec', 'terminal-website_ubuntu_1', 'bash', '-c', command],
23
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
24
- output = result.stdout.decode('utf-8') + result.stderr.decode('utf-8')
25
- print(f"Command output: {output}") # Debugging log
26
- return output
 
 
 
 
 
27
 
28
  if __name__ == '__main__':
29
  socketio.run(app, host='0.0.0.0', port=7860)
 
14
  @socketio.on('input', namespace='/terminal')
15
  def handle_input(data):
16
  command = data['command']
17
+ print(f"Received command: {command}") # Debugging log
18
  result = execute_command(command)
19
  emit('output', {'output': result})
20
 
21
  def execute_command(command):
22
+ try:
23
+ result = subprocess.run(['docker', 'exec', 'terminal-website_ubuntu_1', 'bash', '-c', command],
24
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
25
+ output = result.stdout.decode('utf-8') + result.stderr.decode('utf-8')
26
+ print(f"Command output: {output}") # Debugging log
27
+ return output
28
+ except subprocess.CalledProcessError as e:
29
+ error_output = e.stdout.decode('utf-8') + e.stderr.decode('utf-8')
30
+ print(f"Command error: {error_output}") # Debugging log
31
+ return error_output
32
 
33
  if __name__ == '__main__':
34
  socketio.run(app, host='0.0.0.0', port=7860)