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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InputStream Question

Status
Not open for further replies.

lotsToLearn

Programmer
Jun 10, 1999
9
CA
Hi, <br>
<br>
We use an application called SilverStream to develop and serve our web site. We have some cgi scripts form part of our web site that live outside of the SilverStream environment. <br>
<br>
What I want to do is execute these CGI scripts ( written in perl ) from a servlet. I want the results returned to the servlet and which will then deliver them to the client. I know I need to use input and output streams for this but know very little about there implementation. <br>
<br>
Here is the code that I have. It ain't much but it is a start. <br>
<br>
// Get the runtime object and execute the perl program<br>
Runtime rt = Runtime.getRuntime();<br>
Process p = rt.exec(&quot;D:\\InetPub\\<br>
// Get the inputstream from the process<br>
InputStream is = p.getInputStream();<br>
<br>
// Now this is were I am missing stuff. I need to read the input stream in such a manner that I can write it to the servlets output stream. HELP <br>
<br>
<br>
ServletOutputStream out = res.getOutputStream();<br>
<br>
<br>
I hope that this makes sense to someone out there. <br>
<br>
ALH
 
Hi!<br>
<br>
Do you think something like this?<br>
<br>
import java.io.*;<br>
import java.sql.*;<br>
import javax.servlet.*;<br>
import javax.servlet.http.*;<br>
<br>
public class FromCGIServlet extends HttpServlet {<br>
protected void doGet(HttpServletRequest req, HttpServletResponse res)<br>
throws ServletException, IOException {<br>
BufferedOutputStream out;<br>
Runtime rt;<br>
Process p;<br>
BufferedInputStream in;<br>
String s;<br>
byte[] buff;<br>
int read;<br>
<br>
buff=new byte[4096];<br>
rt=Runtime.getRuntime(); <br>
// p=rt.exec(&quot;D:\\InetPub\\ p=rt.exec(&quot;cmd /c dir&quot;); // I try it with dir<br>
in=new BufferedInputStream(p.getInputStream());<br>
out=new BufferedOutputStream(res.getOutputStream());<br>
while ((read=in.read(buff, 0, 4096))!=-1) {<br>
if (read&gt;0) { out.write(buff, 0, read); }<br>
}<br>
in.close();<br>
out.close();<br>
}<br>
}<br>
<br>
Good luck. Bye, Otto.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top