Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
from flask import Flask, render_template
|
2 |
from flask_socketio import SocketIO, emit
|
3 |
import subprocess
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
app.config['SECRET_KEY'] = 'secret!'
|
7 |
socketio = SocketIO(app)
|
8 |
|
|
|
|
|
|
|
9 |
@app.route('/')
|
10 |
def index():
|
11 |
return render_template('index.html')
|
@@ -13,6 +17,9 @@ def index():
|
|
13 |
@socketio.on('execute_command')
|
14 |
def handle_command(command):
|
15 |
try:
|
|
|
|
|
|
|
16 |
# 执行命令并捕获输出
|
17 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
18 |
while True:
|
|
|
1 |
from flask import Flask, render_template
|
2 |
from flask_socketio import SocketIO, emit
|
3 |
import subprocess
|
4 |
+
import os
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
app.config['SECRET_KEY'] = 'secret!'
|
8 |
socketio = SocketIO(app)
|
9 |
|
10 |
+
# 设置工作目录
|
11 |
+
WORKING_DIR = '/code'
|
12 |
+
|
13 |
@app.route('/')
|
14 |
def index():
|
15 |
return render_template('index.html')
|
|
|
17 |
@socketio.on('execute_command')
|
18 |
def handle_command(command):
|
19 |
try:
|
20 |
+
# 切换到工作目录
|
21 |
+
os.chdir(WORKING_DIR)
|
22 |
+
|
23 |
# 执行命令并捕获输出
|
24 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
25 |
while True:
|