• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

run dos commands through servlet

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
am running the winbach commands through sevlet with help of convert doctool.
i worte the below code.but am not getting any result.


package com.nanna;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletEx extends HttpServlet {

public ServletEx() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=(String)request.getParameter("file1");

try
{
String osName = System.getProperty("os.name" );

String[] cmd = new String[3];

int j=name.length();

String name1=name.substring(0,j-3);



if( osName.equals( "Windows XP" ) )
{
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "ConvertDoc /S"+name+" /F9 /T "+ name1+"TXT /C12";

}
else if( osName.equals( "Windows 95" ) )
{
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = name;
}

Runtime rt = Runtime.getRuntime();
out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");

// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");

// kick them off
errorGobbler.start();
outputGobbler.start();

// any error???
int exitVal = proc.waitFor();
out.println("ExitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTrace();
}
out.flush();
out.close();
}

private String subString(String name, String string) {
return null;
}

public void init() throws ServletException {
// Put your code here
}

}
/*
* Created on Sep 25, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.nanna;

import java.io.*;
public class StreamGobbler extends Thread{
InputStream is;
String type;

StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}

public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
i got this below out put but not any result


Execing cmd.exe /C ConvertDoc /SD:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\BEL.doc /F9 /T D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\BEL.TXT /C12 ExitValue: 1

is their any modifications require.giveme replay to me
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the convertdoc tool in the path of your system?

What I mean to say is: When you start a dos-prompt and you type in convertdoc. Is the command known? If must be known to your webserver. So this means it should be in the path of the webserver (via the webserver startup batch-file or via the system path).
 
madhuri akhi
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need convertion of file one format to another format
like pdf to doc
doc to pdf
so i got one result through one tool and it is working
but is their any possible is their without tool
or any winbatch script is their
it will be working on web application

am waiting for your reply
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry. I can't quite understand your problem!

You are trying to do conversions from pdf to doc and vice-versa? Ok

And I know you are trying to do this in your servlet. Right!

So what's next?

When you have succesfully transformed your document to another format (so you generated a new file) you will have to write the generated document to the browser using the servlet outputstream. (So just read the generated file using File IO), set the correct content type of the servlet outputstream (on the response object call setContentType)and write the file to the client (once again using the response object but now use the getOutputStream method).
 
See where your hand is? Not there. It's next to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic