Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Как запустить EXE из JSP-скрипта? / 3 сообщений из 3, страница 1 из 1
10.02.2006, 08:09
    #33535899
Kulavert
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как запустить EXE из JSP-скрипта?
Сабж? Нужно передать параметры, дождаться завершения, взять сгенерированный им файл и передать его пользователю.
Работает на Tomcat, ось - Win2000.
Заранее прошу прощения, может вопрос очень простой, просто я новичок в JSP, а поиск не дал результата.
...
Рейтинг: 0 / 0
10.02.2006, 09:57
    #33536119
А.Грасоff™
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как запустить EXE из JSP-скрипта?
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
	/**
	 * Converts some important chars (int) to the corresponding html string
	 */
	 static  String conv2Html( int  i) {
		 if  (i == '&')  return  "&";
		 else   if  (i == '<')  return  "<";
		 else   if  (i == '>')  return  ">";
		 else   if  (i == '"')  return  """;
		else return "" + ( char ) i;
	}
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
	/**
	 * Starts a native process on the server
	 * 	@param command the command to start the process
	 *	@param dir the dir in which the process starts
	 */
	 static  String startProcess(String command, String dir)  throws  IOException {
		StringBuffer ret =  new  StringBuffer();
		String[] comm =  new  String[ 3 ];
		comm[ 0 ] = COMMAND_INTERPRETER[ 0 ];
		comm[ 1 ] = COMMAND_INTERPRETER[ 1 ];
		comm[ 2 ] = command;
		 long  start = System.currentTimeMillis();
		 try  {
			//Start process
			Process ls_proc = Runtime.getRuntime().exec(comm,  null ,  new  File(dir));
			//Get input and error streams
			BufferedInputStream ls_in =  new  BufferedInputStream(ls_proc.getInputStream());
			BufferedInputStream ls_err =  new  BufferedInputStream(ls_proc.getErrorStream());
			 boolean  end = false;
			 while  (!end) {
				 int  c =  0 ;
				 while  ((ls_err.available() >  0 ) && (++c <=  1000 )) {
					ret.append(conv2Html(ls_err.read()));
				}
				c =  0 ;
				 while  ((ls_in.available() >  0 ) && (++c <=  1000 )) {
					ret.append(conv2Html(ls_in.read()));
				}
				 try  {
					ls_proc.exitValue();
					//if the process has not finished, an exception is thrown
					//else
					 while  (ls_err.available() >  0 )
						ret.append(conv2Html(ls_err.read()));
					 while  (ls_in.available() >  0 )
						ret.append(conv2Html(ls_in.read()));
					end = true;
				}
				 catch  (IllegalThreadStateException ex) {
					//Process is running
				}
				//The process is not allowed to run longer than given time.
				 if  (System.currentTimeMillis() - start > MAX_PROCESS_RUNNING_TIME) {
					ls_proc.destroy();
					end = true;
					ret.append("!!!! Process has timed out, destroyed !!!!!");
				}
				 try  {
					Thread.sleep( 50 );
				}
				 catch  (InterruptedException ie) {}
			}
		}
		 catch  (IOException e) {
			ret.append("Error: " + e);
		}
		 return  ret.toString();
	}
...
Рейтинг: 0 / 0
10.02.2006, 12:35
    #33536736
Kulavert
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как запустить EXE из JSP-скрипта?
Ща попробуем!
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Как запустить EXE из JSP-скрипта? / 3 сообщений из 3, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]