WAS Liberty Profile 不会 运行 外部进程(使用 Runtime.getRuntime().exec(cmd) )
WAS Liberty Profile won't run external process (using Runtime.getRuntime().exec(cmd) )
如标题所示,WLP 不会 运行 进程 - 它不会 return 进程输入流或错误流的任何内容。
如果有人知道需要进行的配置,我很想知道..
(注意过程可以 运行 通过 运行 手动执行命令 - 此外,整个过程 运行 在 tomcat8 上很顺利所以..)
编辑 1:
问题不是你们所说的WLP下的命令执行,所以我接受了答案。
问题不同:我将一个媒体文件发送到一个多部分 servlet,并使用以下代码将其存储在磁盘上的一个文件中:
InputStream is = request.getInputStream();
String currentTime = new Long(System.currentTimeMillis()).toString();
String fileName = PATH + currentTime + "." + fileType;
File file = new File(fileName);
// write the image to a temporary location
FileOutputStream os = new FileOutputStream(file);
byte[] buffer = new byte[BUFFER_SIZE];
while(true) {
int numRead = is.read(buffer);
if(numRead == -1) {
break;
}
os.write(buffer, 0, numRead);
os.flush();
}
is.close();
os.close();
并且文件与以下前缀一起保存:
虽然这不会发生在 tomcat8 上(使用相同的客户端)..
在接收到的输入流中有些事情不是微不足道的。 (请注意,它是一个仅通过 @MultipartConfig 设置的多部分 servlet)
希望这篇文章post能对其他人有所帮助..
伙计们,谢谢你的帮助!
这将适用于 Liberty。我能够在 servlet 中测试以下代码,它打印了我当前目录的路径:
String line;
Process p = Runtime.getRuntime().exec("cmd /c cd");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
从像这样的简单命令开始,当您转向更复杂的命令或脚本时,请确保您没有隐藏可能会返回的异常。始终至少打印堆栈跟踪!
如标题所示,WLP 不会 运行 进程 - 它不会 return 进程输入流或错误流的任何内容。 如果有人知道需要进行的配置,我很想知道.. (注意过程可以 运行 通过 运行 手动执行命令 - 此外,整个过程 运行 在 tomcat8 上很顺利所以..)
编辑 1: 问题不是你们所说的WLP下的命令执行,所以我接受了答案。
问题不同:我将一个媒体文件发送到一个多部分 servlet,并使用以下代码将其存储在磁盘上的一个文件中:
InputStream is = request.getInputStream();
String currentTime = new Long(System.currentTimeMillis()).toString();
String fileName = PATH + currentTime + "." + fileType;
File file = new File(fileName);
// write the image to a temporary location
FileOutputStream os = new FileOutputStream(file);
byte[] buffer = new byte[BUFFER_SIZE];
while(true) {
int numRead = is.read(buffer);
if(numRead == -1) {
break;
}
os.write(buffer, 0, numRead);
os.flush();
}
is.close();
os.close();
并且文件与以下前缀一起保存:
虽然这不会发生在 tomcat8 上(使用相同的客户端).. 在接收到的输入流中有些事情不是微不足道的。 (请注意,它是一个仅通过 @MultipartConfig 设置的多部分 servlet)
希望这篇文章post能对其他人有所帮助..
伙计们,谢谢你的帮助!
这将适用于 Liberty。我能够在 servlet 中测试以下代码,它打印了我当前目录的路径:
String line;
Process p = Runtime.getRuntime().exec("cmd /c cd");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
从像这样的简单命令开始,当您转向更复杂的命令或脚本时,请确保您没有隐藏可能会返回的异常。始终至少打印堆栈跟踪!