running command line commands with arguments...

Discussion in 'Java' started by doneirik, Feb 16, 2007.

  1. doneirik

    doneirik Guest

    Dear forum,

    I need to run a command line like command with arguments in the java
    code.
    Now I have things stored in a .bat file that I execute , however, I
    would like to run everything from the java code itself. Would that be
    possible?

    java code:
    Runtime r = Runtime.getRuntime();
    try
    {
    String s = "latTest.bat";
    r.exec(s);
    }
    catch (Exception ioe)
    {}

    bat file:

    @ECHO OFF

    cd c:\Program files\MikTex 2.5
    pdflatex C:\Temp\testfile.tex
    testfile.pdf
     
    doneirik, Feb 16, 2007
    #1
    1. Advertising

  2. On 15 Feb 2007 23:19:31 -0800, doneirik wrote:
    > I need to run a command line like command with arguments in the java
    > code. Now I have things stored in a .bat file that I execute ,
    > however, I would like to run everything from the java code itself.
    > Would that be possible?


    Yes. Have you not read the API documentation for Runtime.exec()?

    String cmd = "pdflatex C:\\Temp\\testfile.tex testfile.pdf"
    File dir = new File("C:\\Program files\MikTex 2.5");
    Process p = Runtime.getRuntime().exec(cmd, null, dir);

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Feb 16, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,772
    Terry Hancock
    Apr 23, 2005
  2. crypto
    Replies:
    4
    Views:
    4,715
  3. Ivan Shevanski
    Replies:
    3
    Views:
    407
    Mike Meyer
    Jul 1, 2005
  4. Ivan Shevanski
    Replies:
    1
    Views:
    401
    Peter Hansen
    Jul 1, 2005
  5. Peter A. Schott
    Replies:
    8
    Views:
    515
    Bengt Richter
    Nov 12, 2005
Loading...

Share This Page