@tanskong/office-assistant 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server.py +9 -1
package/package.json
CHANGED
package/src/server.py
CHANGED
|
@@ -11,6 +11,7 @@ We are not responsible for data loss when operating on original file locations.
|
|
|
11
11
|
|
|
12
12
|
import sys
|
|
13
13
|
import os
|
|
14
|
+
from io import StringIO
|
|
14
15
|
|
|
15
16
|
from license_manager import verify_license
|
|
16
17
|
verify_license()
|
|
@@ -184,10 +185,17 @@ def run_python(code: str, app_name: str = "Excel") -> dict:
|
|
|
184
185
|
doc = _get_active_doc(app, app_name)
|
|
185
186
|
globals_dict = _build_globals(app, doc, app_name)
|
|
186
187
|
|
|
188
|
+
# Capture stdout to return print output
|
|
189
|
+
old_stdout = sys.stdout
|
|
190
|
+
sys.stdout = buffer = StringIO()
|
|
191
|
+
|
|
187
192
|
try:
|
|
188
193
|
exec(code, globals_dict)
|
|
189
|
-
|
|
194
|
+
output = buffer.getvalue()
|
|
195
|
+
sys.stdout = old_stdout
|
|
196
|
+
return {"success": True, "output": output or "(无输出)"}
|
|
190
197
|
except Exception as e:
|
|
198
|
+
sys.stdout = old_stdout
|
|
191
199
|
return {"success": False, "error": str(e)}
|
|
192
200
|
|
|
193
201
|
|