Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP Hangs ...

Status
Not open for further replies.

aahan

Programmer
Mar 28, 2002
15
US
Hi,

I've a class as under , which is getting run from a JSP. The JSP is providing the Batch File to Run :

==========================================================
Code:
public int runbat(String batchfilename) throws Exception{
Runtime rt = Runtime.getRuntime();
String cmd="E:\\myweb\\" + batchfilename;
Process proc = rt.exec(cmd);
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<OUTPUT>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</OUTPUT>");
int exitVal = proc.waitFor(); 
System.out.println("Process exitValue: " + exitVal);
return(exitVal); 
}
==========================================================
and this is the windows batch file :
==========================================================
Code:
SET @LOGFILE="E:\myweb\SIMPLE.BAT.LOG"
ECHO. >>%@LOGFILE%
dir >>%@LOGFILE%
ECHO Commencing FTP... >>%@LOGFILE%
C:\WINNT\SYSTEM32\FTP.EXE -s:ftp_xyz.scr xyz.com >>%@LOGFILE%
ECHO .................................................>>% @LOGFILE%
==========================================================
This works fine, if I run this batch file by itself from the DOS Prompt, however , hangs if I am calling it from a JSP. This was working fine without the ftp command in the batch file from the jsp ( the dir by itself was working ok )

Any help would be appreciated.

Thanks.
 
Security has probably noticed the access to the system32 dir and spazzed out on you.

It would be better to use a Java FTP implementation. Check out :



Or, as this article says, you can do this {UNTESTED]:

Code:
URL url = new URL("ftp://user01:pass1234@ftp.foo.com/README.txt;type=i");
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload

good luck,

Matt
 
Some tips:

1.- Test the bat itself from the command line.
2.- Make sure the command String is being properly constructed.
3.- Remember that those scripts run server side
4.- Try a different bat file
5.- Try creating a new Thread
5.- Post a more specific error: exception, where it hangs, error messages, ...

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top