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.

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

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How to run a DOS command from an Oracle form.

    How can I run a DOS command from an Oracle form (i.e. open the calculator located at c:\windows\system32\calc.exe)?

    first of all get the environment variable for the c:\windows\system32 direcotry for any of the windows
    you can use get variable from the ora env package
    now cancat the system32 variable with the calc.exe string
    now pass the string with host command as parameters
    this process will work for all type of windows.

  • How can I run a dos command from java on windows 98, 95?

    The usage of cmd.exe in the java program to run a dos command on windows 98. 95 doesn't work as the equivalent command is command.exe
    But using the command.exe in the java program makes my program to hang.

    hi,
    As u mentioned, u cannot use the cmd.exe in win9x environment as cmd.exe is specific to windows NT, you can use the command.exe without any hitches.
    for eg
    java.lang.Runtime.getRuntime().exec("start command /K a.bat"); should run the batch file a.bat..
    if the problem persists, try posting the snippet of code that you are using.
    cheerz
    ynkrish

  • Running the Batch Processor from a Java application (on schedule)

    Hello,
    I would like to run the Batch Processor (on schedule) from a Java application -- not from the Command Prompt.
    To achieve that, I suppose I would need to call a certain function contained in engine/determinations-batch.jar, using perhaps the path to the config xml as an argument.
    The trouble is that the OPA developer's guide doesn't mention it (or at least I didn't find it).
    Could you help me out?
    Thanks in advance.
    Razvan

    RazvanSaftescu wrote:
    Thanks Frank, but is there a way to identify this method and its syntax? I didn't find anything so far on the internet or on the dev's guide.
    This is the Java main method for the determination-batch.jar file - so the main method has the syntax:
    public static void main(String[] args)
    args is an array of strings matching the command line arguments described in the OPA Developer's Guide topic "Configure the Batch Processor".
    Regards,
    Brad

  • Running a DOS Command through a JAVA GUI

    I'm trying to run a command line through a GUI.. how would i go about doing this... suppose i wanted to run the following dos command inside a java program:
    String command = "jar cvf classes.jar open.java close.java"
    Does anyone have a good model I can look at that can implement a dos command?

    Maybe you can refer to this resource , I can not remember the Class, It seems like this Runtime.getRuntime().exec() ?? It can execute your command.

  • 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 to run multiple DOS commands from a single Webutil Client_Host session?

    Hello all,
    I have a requirement where I need to create an interface with SVN from Forms for basic checkin-checkout of files.
    So, I've been trying to use webutil client_host to open a command line session and issue svn commands.
    For svn, sometimes I need to give multiple commands like change to a particular directory and then run an svn command.
    But client_host takes in only one command at a time and I'm unable to issue a series of DOS commands to perform
    a particular task.
    Is there a way to do this?
    Pls suggest.
    Regards,
    Sam

    First your original question... You can put more than one DOS command on a single line, simply separate each command with an ampersand (&). For example:
    mkdir c:\abc & cd abc & dir*
    Regarding your concerns about performance, well that would depend on exactly what you mean. Using CLIENT_HOST (or HOST on the server) simply opens a shell (DOS in this case) then passes your command to it. The performance of performing this action really isn't measurable. Basically you are just pressing a button and you should get a near immediate action. As for the performance of executing each command, that has nothing to do with Forms. Once the command is passed to the shell, the rest is a function of the shell and whatever command you passed.
    Having said that, if you were to write something sloppy like a loop (in pl/sql) which called CLIENT_HOST lots of times repeatedly, then yes there would be a performance problem because the pushing of the button will cause an exchange to and from the server and each cycle in the loop will do the same.
    So the answer to how performance is impacted will depend on what exactly you need to accomplish. If it is a single call to CLIENT_HOST, this should be fine.

  • 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".

  • 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.

  • Running ssh command in a java application

    Hi there!
    I am trying to run a ssh command from a java application cause I need to store the result.
    Actually I can run this command in the cygwin shell so I need to open the shell and run the command, all trough java.
    so, what my process needs to do is:
    1) open the cmd
    2) run C:\cygwin\cygwin.bat
    3) execute the ssh command
    ssh -l fip-user ipdb fip 42704) print the result of the ssh command.
    Note that the cygwin opens in the same command line window and so will print it's result to the same process inputstream
    Message was edited by:
    RBervini

    Use "Runtime.getRuntime().exec()" to execute the SSH program,
    and you can then get the output of the SSH program
    via the getInputStream() method on the returned Process object.
    Note: there are many pitfalls with this. In particular, most people don't know
    they should create separate threads to drain the input/output pipes.
    See this excellent classic article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    on how to do it right.

  • Running a windows command line in java?

    Hi guys.
    I wonder if there's a way to run windows (dos) commands from within java. the code goes like:
    if (setting == true) {
    run dos command "ECHO Command is activated and running."
    please reply if you are able to help out. thanks a lot
    - n3phi|im`

    note that in some cases you can use a normal
    Runtime.exec ("program arg1 arg2");
    but in some cases the commands are built into the shell, so you have to do
    Runtime.exec ("command.com /c copy myfile here");
    "copy" is one of them, and "echo" is probably one too. The latter should work for all programs and commands, but might involve some overhead as a new instance of 'command' is created and destroyed for every command.

  • DOS command from a WebDynpro

    hi,
    How can i call a DOS command from a WebDynpro Application. I tried this piece of code but it does not work.
    Runtime.getRuntime().exec("cmd/c help");
    Can somebody guide me with the same.
    Thanks,

    Hi,
    From Webdynpro its not possible until and unless its uploaded to the server.
    Due to the following reasons
    WD code runs in the server.
    No client side scripting possible in WD.
    Regards
    Ayyapparaj

  • 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.

Maybe you are looking for

  • Nav bar and headers not showing up in IE9

    After I select the ActivX option "allow blocked content" the navigation bar and white headlines disappear in the IE9 browser. Any thoughts or suggestions? Thank you! www.moxiespeak.com/indextest

  • IMac is sluggish

    My iMac is sluggish and stalling, needs to be rebooted often? This just happened suddenly last week and now it happens everyday.

  • Multiple sales order  with single invoice

    Hi ! For the same dealer can we make single Invoice dispatching  with multiple sales order ???  and How ? Thanks.

  • Integration of ERP with Office365

    Hi, Is there a way in which we could integrate a third party ERP system into Office 365 using SharePoint, so that we could have data from ERP to be populated in SharePoint apps?

  • JSR 168 compliance

    Hi, I wish to test the JSR 168 compliancy of the code. Is there a plug-in available in JDeveloper with which i could test this. Mukta