From 7593f67fdf2a99f4a2a786f200f076ed623739ab Mon Sep 17 00:00:00 2001 From: whb <17803890193@163.com> Date: Mon, 5 Aug 2024 15:53:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0io=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/stu/JupyterhubController.java | 90 ++++++++++--------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/JupyterhubController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/JupyterhubController.java index 10dbeab..e81a606 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/JupyterhubController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/JupyterhubController.java @@ -176,8 +176,10 @@ public class JupyterhubController { String filepath = "/etc/jupyterhub/data/" + caseName + "/data/"; - - + File directory = new File(filepath); + if (!directory.exists()) { + directory.mkdirs(); + } //设置数据文件 if (dataFile != null && !dataFile.isEmpty()) { @@ -186,48 +188,48 @@ public class JupyterhubController { iFileUtil.uploadResource(file, filepath, null); - try { - // 创建 chmod 命令以递归方式修改权限 - String[] command = {"chmod", "-R", "777", filepath}; - // 创建一个新的进程来执行Python代码 - Process process = Runtime.getRuntime().exec(command); - - - // 获取进程的输入流 - BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); - - // 获取进程的输出流 - BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); - - - // 读取Python代码的输出 - String line; - StringBuilder output = new StringBuilder(); - while ((line = inputStream.readLine()) != null) { - output.append(line).append("\n"); - } - - // 读取Python代码的错误信息 - StringBuilder errors = new StringBuilder(); - while ((line = errorStream.readLine()) != null) { - errors.append(line).append("\n"); - } - - // 等待进程执行完成 - int exitCode = process.waitFor(); - - if (exitCode == 0) { - // 执行成功,输出Python代码的结果 - System.out.println("权限修改成功!"); - - } else { - // 执行失败,输出错误信息 - System.err.println("权限修改失败了!\n" + errors.toString()); - - } - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } +// try { +// // 创建 chmod 命令以递归方式修改权限 +// String[] command = {"chmod", "-R", "777", filepath}; +// // 创建一个新的进程来执行Python代码 +// Process process = Runtime.getRuntime().exec(command); +// +// +// // 获取进程的输入流 +// BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); +// +// // 获取进程的输出流 +// BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); +// +// +// // 读取Python代码的输出 +// String line; +// StringBuilder output = new StringBuilder(); +// while ((line = inputStream.readLine()) != null) { +// output.append(line).append("\n"); +// } +// +// // 读取Python代码的错误信息 +// StringBuilder errors = new StringBuilder(); +// while ((line = errorStream.readLine()) != null) { +// errors.append(line).append("\n"); +// } +// +// // 等待进程执行完成 +// int exitCode = process.waitFor(); +// +// if (exitCode == 0) { +// // 执行成功,输出Python代码的结果 +// System.out.println("权限修改成功!"); +// +// } else { +// // 执行失败,输出错误信息 +// System.err.println("权限修改失败了!\n" + errors.toString()); +// +// } +// } catch (IOException | InterruptedException e) { +// e.printStackTrace(); +// } }