How to run dos command in jsp

hi all,
i am running this command at command prompt
like below
java filename argument.
ex: java validateuser user1
it works fine at command prompt. and the same command i want to run in jsp
so i tried like this
Runtime x = Runtime.getRuntime().exec("java validateuser user1");
whats happenning here is it just opening command promot of java.exe but its not running validateuser.
any help will be greatly appreciated.
advance thanks.

why on earth are you trying to run java.exe on the command line through JSP?i think you misunderstand my question.
i am not trying to run java.exe on through jsp.
I am trying to run a validateuser user1 in jsp .
Note:validateuser is a java file which take one argument.here in my scnerio user1 is the argument.

Similar Messages

  • How to run DOS command in Java environment?

    Can i run DOS command in Java environment?
    I did like this:
    Runtime r = Runtime.getRuntime();
    r.exec("cmd.exe");
    r.exec("set classpath=%CLASSPATH%;.\\tmp")
    but failed.
    However if I run the java command, it runs successfully.
    r.exec("javac Test.java");
    r.exec("java Test");
    how should I do so that i can run the DOS commands metioned above in Java Environment?
    thanks a lot.

    Have a look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    This may help. I wonder if this is ok ?
    Runtime r= Runtime.getRuntime();
    r.exec("cmd.exe /C set classpath=%CLASSPATH%;.\\tmp\"");

  • How to run dos command on java

    would java run the dos command ?
    if yes ~would you mind give me some example~please~

    ..or just use:
    Runtime.getRuntime().exec("cmd /c commandyouwanttouse");
    Hope it works!                                                                                                                                                                                               

  • How do run dos command from form

    Hi all,
    I need to run a file.bat (dos), someone can help me, please?
    I know the command HOST(..), but when execute the command exit a black window. Are there other command?
    Thank you
    Silvia

    Hello,
    I know the command HOST(..), but when execute the command exit a black window. Are there other command?Version Dependent.
    For less then or equal 6i version
    HOST('CMD /C C:\batch_file_name.bat');For the web based...
    The same above command will work for AS level. If you need on client side then
    CLIENT_HOST('CMD /C C:\batch_file_name.bat');-Ammad

  • Running DOS command from JAVA

    Hi ,
    I would appreciate if anyone could tell me how to run DOS command such as "del" using JAVA language .Thank you.

    <steps onto soapbox>
    Surely for something like 'del' we should be advocating a non-OS specific method so we don't lose sight of Java's cross platform abilities.
    If it has to run an OS specific thing fine, but please look for a non OS specific solution first.
    <steps off soapbox>

  • Is there a way to run dos commands on onther system?

    Hi I have connected to a port of another system where windows is the operating system. So can I run dos commands on the other system through that network connection from my computer?

    I'm not sure what you mean by "connected to a port of another system" . Which port using what software to which server?

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How java runs in command prompt and why java runs on it

    how java runs in command prompt and why java runs on it

    command prompt was used before the development of IDEs like RAD,eclipse etc.
    its still used for better understanding of the compilation and errors.
    type the java file and save the file(source file) in the bin folder of ur jdk environment with extension .java. the source file must be the one that has the main method declared.
    in the cmd prompt screen , set the path of bin folder.
    eg:C:/program files/jdk(some version)/bin/...
    for compilation,type:
    javac (source file_name).java and press enter
    for running the file:
    java source file_name

  • How can one run OS commands from JSP's?

    Hi
    I figured out the perms problem I had, and running a java class that calls Runtime.exec() now works - apparently; in fact, it doesn't really run the OS command, but returns "OK".
    Anyone have an idea how to make it actually run?
    Thanks,
    Paulo

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Paulo Rodrigues ([email protected]):
    Hi
    I figured out the perms problem I had, and running a java class that calls Runtime.exec() now works - apparently; in fact, it doesn't really run the OS command, but returns "OK".
    Anyone have an idea how to make it actually run?
    Thanks,
    Paulo<HR></BLOCKQUOTE>
    Hi Paulo, i use for that function the following code:
    // JDC Tech Tips February 15, 2000
    import java.io.*;
    import java.util.ArrayList;
    public class ExecDemo {
    static public String[] runCommand(String cmd)
    throws IOException {
    // set up list to capture command output lines
    ArrayList list = new ArrayList();
    // start command running
    Process proc = Runtime.getRuntime().exec(cmd);
    // get command's output stream and
    // put a buffered reader input stream on it
    InputStream istr = proc.getInputStream();
    BufferedReader br =
    new BufferedReader(new InputStreamReader(istr));
    // read output lines from command
    String str;
    while ((str = br.readLine()) != null)
    list.add(str);
    // wait for command to terminate
    try {
    proc.waitFor();
    catch (InterruptedException e) {
    System.err.println("process was interrupted");
    // check its exit value
    if (proc.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    br.close();
    // return list of strings to caller
    return (String[])list.toArray(new String[0]);
    public static void main(String args[]) throws IOException {
    try {
    // run a command
    String outlist[] = runCommand("rm ./dummy");
    // String outlist[] = runCommand("ls");
    // display its output
    for (int i = 0; i < outlist.length; i++)
    System.out.println(outlist);
    catch (IOException e) {
    System.err.println(e);
    Gert
    null

  • HOW DO I RUN DOS COMMANDS ON JAVA

    I SWEAR, I'LL PAY YA IF YOU HELP ME!!!
    Hi, this is the thing:
    have you ever run the "time" command on a DOS console?? if you have, you know that it shows the current time, and lets you set a new time.
    well, i need to make a java program to open a DOS console and execute the command, and making it able to write in information on the console so it sets a new time.
    MY PURPOSE IS NOT JUST WATCHING THE CURRENT TIME!! so please don't tell me to use System.getCurrentTimeMillis() or something like that; i explicitly need to run that DOS command. what's the Java code to do it??
    thank you!! and please attach your account # so you get a $50 deposit by the end of the week
    thank you!!

    Thanks a lot, you all guys, but i don't know what's with this thing.... it always throws an IOException, with the following exception stack trace:
    java.io.IOException: CreateProcess: temp.bat error=0
            at java.lang.Win32Process.create(Native Method)
            at java.lang.Win32Process.<init>(Win32Process.java:63)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:550)
            at java.lang.Runtime.exec(Runtime.java:416)
            at java.lang.Runtime.exec(Runtime.java:358)
            at java.lang.Runtime.exec(Runtime.java:322)
            at Tarea.main(Tarea.java:15)and it will come out the same shit over and over. The above case was thrown by the line Runtime.getRuntime().exec("temp.bat") where temp.bat is a file where the only thing written in it is the word "time". and you can change the string parameter of the method exec, and thats what will change in the stack trace above.
    I also tried "cmd", "command", and "command.com". With the last one, it opens the command.com application but it freezes and does nothing. With the other two, appears the same old shit from above.
    Please help me!!
    Thank you...

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    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, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // 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();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

  • How to run a command line argument

    i want to run a command line argument, say for eg......i want to execute the "dir" command on the dos prompt and capture the output.
    how can i do this.
    actually i want to capture the output of the ping command and write it to a file. can any body plsssssss help

    This command runs a ping to "address" and writes the output back to the command line. To capture it, just put strings into an array or do whatever you want with it. If you want to wait until the program completes before reading its input, use p.waitFor().
    Process p = Runtime.getRuntime().exec("ping " + address);
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String currLine = null;
    while((currLine = in.readLine()) != null)
      System.out.println("ping: " + currLine);
    [/code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Running Dos Command using Java

    How do i run a particular Dos command using a simple java class?

    Process process = Runtime.getRuntime().exec( ... );
    Search the forum. There are plenty of examples.

  • Doesn't it get very old, same question about running dos command?

    To everyone who is tooo lazy to search.
    Process p = Runtime.getRuntime().exec("progname arg1 arg2");
    What a wast of everyone's time responding to the same question on how to run a dos command.

    I think you'll find it's
    Runtime.getRuntime().exec(new String[]{"progname", "arg1", "arg2"});

  • Executing a DOS Command from JSP

    How do i execute a Dos command from within JSP. I would like to execute a sql Loader command .
    Thanks

    You use Runtime.execute().
    Take a look here for a few of the tricks involved in it:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Maybe you are looking for

  • Client can not communicate with MP over https. Certification Problem

    Hi All, I have been fighting with this problem for the last 3 days and couldn't solve yet. So, I hope we can solve it here. I am trying to install client manually from a usb drive by using the below command.  Ccmsetup.exe /usepkicert smsmp="srvsccm20

  • How to insert a CLOB in Oracle8.0 with JDBC

    Hi, I'm having trouble to insert a CLOB into a table with java. I'm using JDK1.1.8 and Oracle8.0 I've to insert more 4000 char String into that field. What can I do? Any example is very appreciate.

  • Generic Object Services restrict user access

    Hi I have the following scenario, could anyone offer any pointers as to how to achieve a solution. I have two groups of people, A and B, my requirement is to only allow group A to access/delete documents that have been created by users in group A, an

  • Lightroom 4.4 Problems

    I updated from Lightroom 4.3 to 4.4. When I'm using vibrance or saturation in the 'Develop' mode then switch back to 'Library' mode I loose all the Vibrance I just added to the photo. I can even blow out the colors and when I go back to Library mode

  • Used dc and public part concept not working in ess

    Hi, I tried using the ess address dc(of US country) as used dc in w4 dc(US country) and did all steps of making address dc as public part and added it as used DC in W4, when i tried to get the address dc context in to w4 by calling the read method( o