Executing DOS command from within java.

I have an XML file and an XSLT stylesheet.
I want to process this XML file using XSLT stylesheet from java. Using saxon.
Here is the java class I wrote --
class DOSCommand {
public void exec_command(String[] cmd) {
try {
Process child = Runtime.getRuntime().exec(cmd);
} catch (IOException e){
System.out.println("Error");
System.out.println(e.getMessage());
finally{
System.out.println("Finally");
In my servlet class I am instantiating the DOSCommand object and calling the method
DOSCommand d = new DOSCommand();
String[] c = {  "c:\\Program Files\\saxon\\saxon.exe", "-o",
"PO.html", "ePO.xml", "POE.xsl"
d.exec_command(c);
But I am not getting results. It does not give any error. But does not process the XML file and the Date/timestamp of PO.html does not change.
I know that Definition/Creation of DOSCommand object is not necesssary here. But we can disregard it.
Please let me know where I am going wrong !
Avinash.

Probably where you are going wrong is in failing to specify your working directory, so your command can't find "PO.html" and so on in the default working directory for that command. But that's not really the answer. The answer is not to do it in that way in the first place. Saxon has a Java API and its documentation has a section entitled "Embedding Saxon in an application".

Similar Messages

  • Can we execute DOS Commands from a Java Application

    I just want to know whether we can execute DOS Commands from a Java Application.
    Thanks.

    hi,
    try this:
    Runtime.getRuntime().exec("cmd /c start abc.bat");
    andi

  • Execute DOS command from SAP

    hi experts ,
    i need to execute DOS command from SAP .
    earlier we have 'GUI_EXEC' WS_EXECUTE , 'WS_DOWNLOAD' etc which are Obsolete now.
    as we are using ECC6.0. kindly guide how to do this.
    best regards,
    Rahul

    Try out...
    DSVAS_DOC_WS_EXECUTE_50
    or
    CL_GUI_FRONTEND_SERVICES=>EXECUTE
    <b><REMOVED BY MODERATOR></b>
    Thanks & Regards
    ilesh 24x7
    Message was edited by:
            Alvaro Tejada Galindo

  • Execute shell command from within pascal code

    Hello there,
    I am trying to execute a shell command from within my pascal code. I use XCode together with FreePascal. I have tried something like:
    exec ('program', 'options');
    adding the 'Dos' unit to the Uses clause of my program.
    Thus, e.g.,
    exec ('mkdir', '/A')
    to create a directory with the name 'A'.
    However, my attempts so far were unsuccessful. Can anyone help me on this, and perhaps provide a simple example of how to do it right?
    Thank you in advance,
    Shane

    In the mean time, I found the problem myself. I am just posting the solution here for anyone that is interested. My original solution was correct, in that the 'Dos' Unit must be added, and that the right command is 'exec'. There was however a problem with the correct path to the program that I wanted to invoke. In the shell, this program was accessible from anywhere. However, in the 'exec' command, the full path to the program must be given. Since I am not a Unix expert, I don't know the reason for this.
    So, in summary, the solution is:
    Uses Dos;
    begin
    exec ('full path to program', 'program options');
    e.g.: exec ('/bin/sh', '/run.sh') to process the commands in the file /run.sh
    end
    Hope this may be of help to anyone else.
    Shane
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)

  • Runnig DOS commands from the java code?

    Hi reader,
    how can I execute DOS commands (I am on an Windows XP Machine) from my java code and also capture the output?
    I think the
    runtime.exec(command)
    only executes win32 processes.
    Please suggest
    TIA
    Ayusman

    Again, this link should tell you most of what you need to know:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    You're not limited to the Win32 platform unless you're using specific DOS commands. Perhaps if you're just after file system information then some of the classes in the java.io package can help.
    If it's not enough, perhaps a resource bundle or something similar can provide you with the names of the external programs you need to run, i.e. "dir" for win and "ls" for *nix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Executing OS command from within PL/SQL...

    Hi
    I would like to know if you can issue operating system command
    from within a PL/SQL block on Oracle Database(not developer
    2k) .Is there any built in package for the same ? Like a similar
    command is available in forms i.e HOST .
    Can anyone help please ?
    Thank You
    Cheers
    Raghavendra
    null

    The only documentation I have seen uses dbms_pipe which
    communicates with a host 3gl program, usually C, which in turn
    issues a call to the c function system(). You could also mimic
    these same actions without using dbms_pipe by using a extproc
    program linked to the database if you are running db version 8.0
    or above. See the pl/sql procedure manual for dbms_pipe examples.
    Raghavendra (guest) wrote:
    : Hi
    : I would like to know if you can issue operating system command
    : from within a PL/SQL block on Oracle Database(not developer
    : 2k) .Is there any built in package for the same ? Like a
    similar
    : command is available in forms i.e HOST .
    : Can anyone help please ?
    : Thank You
    : Cheers
    : Raghavendra
    null

  • Execute DOS command from java application

    Hello,
    I want to execute a DOS command (MOVE, in order to move an image from a folder to an other) from a java application. How can I do this?
    Francesco

    Yes I have tested it and it is working but only when executing a bacth file. For instance:
    Runtime rt = Runtime.getRuntime();
    try{
         Process proc = rt.exec("move.bat");
    }catch(Exception ex){
         ex.printStackTrace();
    }and the command in move.bat is:
    move c:\\temp\\*.gif C:\\temp2
    You don't have to use double slashes in batch files, only in Java. But anyway it is working both ways.
    It is not working when you try to execute the command without the batch file:
    Process proc = rt.exec("move c:\\temp\\*.gif C:\\temp2"); -> this will not work.
    It should work. Try to execute another command to see what happens.

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

  • How does one execute unix commands from within an applet?

    Greetings Folks,
    I've written a simple java applet that runs a unix command and then displays some information. The applet compiles fine, and runs perfectly from the command line on my unix system.
    However, when I point a browser at the applet from my desktop PC I get the following error as taken from the java console:
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)
    This is of course the first line in a long line of error messages. It appears that I am not able to execute a command on the unix system through my applet. I know the problem is with trying to execute a unix command since commenting it causes no error in the web browser. This is the command I'm using in java to execute the unix command:
    p = Runtime.getRuntime().exec("ps");
    Here's the html file on the unix system:
    <html>
    <head></head>
    <body>
    <appletcode=G.class height="250" width="400">
    Your browser does not support the applet tag.
    </applet>
    </body>
    </html>
    I won't list the java code since it is compiling and working on the command line. But, if you want to see it I'll provide it.
    I've done quite a bit of research on this and it seems that a great number of people have similar problems reading or executing files through java. I have yet to find a solution to this problem.
    Here are some details about my setup:
    Server:
    HP9000 running HP/UX 11.23
    Apache Web Server 2.0.35
    Java 1.5
    Desktop PC:
    Win2K Pro
    Internet Explorer 6
    Java 1.6
    If you have a solution I would be very grateful! This problem is keeping me from writing my application!
    thanks!
    kev

    Multi-posted.
    Already answered here http://forum.java.sun.com/thread.jspa?threadID=5225314&messageID=9916327#9916327
    Please don't multipost again!

  • Execute DOS command from Java Code

    Hi All
    I am developing a Java application where I am launching some external Windows application on click event of a button.
    I am able to launch that application, but now I have to keep a check that if once that application is launched on clicking the button, then next time it should not launch. But if user exits that external application, then on clicking the button that application should be launched. I tried several ways but i am not able to keep track of that process which makes that application run. The major problem is that when that application is being launched and running, i don't have anything to read or write to that process's Input Stream or Output Stream. Can any one help me out in this????

    ApratimSharma wrote:
    You Might not get anything in the inputstream.read but when the external application will exit you will definitely get EOF (int -1). However Important thing here is that inputstream.read is a blocking call so better do it in a separate thread.
              Runtime runtime = Runtime.getRuntime();
              try {
                   Process process = runtime.exec("calc");
                   InputStream inputStream = process.getInputStream();
                   if (inputStream != null) {
                        System.out.println("Running");
                   while (inputStream.read() != -1);
                   System.out.println("Exited");
              } catch (Exception e) {
                   e.printStackTrace();
              }Now that is what I call 'stating the obvious' !
    You need to read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement ALL the recommendations.
    Edited by: sabre150 on Oct 8, 2009 10:00 AM

  • Executing jar command from the java application

    Hi All,
    In my application i want to create a jar file with the existing class @ Runtime and want to download . But i tried to execute the jar command via Process.getRuntime, it throws IOException. Please guide me or give the solution

    PavithraKarthikeyan wrote:
    Please guide me or give the solutionQuestion your need for this. Why do you think you need to create the jar file.
    P.S. The jar command is only available if the user has the JDK installed so if he has only the JRE installed then you have a problem using Runtime.exec(). There are classes (java.util.jar.JarFile et al) that will allow you to jar files using Java code.

  • Problem  in  executing dos command from runtime.exec(String command);

    Hi
    i have wriiten a code for running command of DOS-Promt
    try
         rnt1 = Runtime.getRuntime();
                                  proc1= rnt1.exec("myb");//myb is a batch file      and proc1 is process class instance
                                                                try
                                  proc1.waitFor();
                                  catch (InterruptedException e)
                             System.out.println("InterruptedException raised: "+e.getMessage());
                   catch (IOException ioe)
              System.out.println("IOException raised: "+ioe.getMessage());
    But it is giving error while running:
    this is showing as an IO exception
    CreateProcess: myb error=0
    Please help me how to proceed
    Thanks

    There are 2 possible reasons (perhaps concurrent):
    1. The file to be executed is not in the same path of your application, and you MUST specify its whole absolute path as exec() argument;
    2. The file to be execute is really (as you call it) a DOS batch file, and then it HAS TO BE NAMED (and called) myb.BAT or (under NT/2000) myb.CMD; WinDOS is Not Unix (WNU): extensions rule!!!

Maybe you are looking for

  • JSPM Error while applying As Java Patch to PI 7.1

    Dear All I am facing an issue when trying to patch new Pi 7.1 Ehp1 Java patch through JSPM steps i did . since the download manger is not working for us i click on the link and down load all the patches to windows machine ( Installed machine is AIX)

  • I tryed to turn off find my iphone but it says my device is offline i forgot my iphone passcode so how can i go online?

    i broke my iphone screen two months ago, that being said its been dead for awhile i recently recharged it but now i dont remeber my passcode that i put on there. i did the whole deleting the find myiphone thing from icloud but its telling my it will

  • No Ranges its very urgent

    Dear All, If i have to assign no ranges to differnet document types for that can i use Sr. No. from 45 onwards(where i assign no ranges to them)? Bcoz is ther any link between SD& MM in no ranges.MM no ranges start with 45 sr. no onwards. so is there

  • Since installing IOS6 autofill won't work in Safari.

    Since installing IOS6 on my Ipad3, autofill won't work in Safari.  It used to fill my name and address.  Please help! I've enabled Autofill, switched off Private Browsing, turned off Block Pop Ups...it was fine till I began with IOS6.

  • Consumption of finished goods

    Hi All, I notice the posting of co11n is dr consumption finished goods cr finished goods account. May I know why there is such an accounting posting? Thanks