Calling .NET exec from Java

Discussion in 'Java' started by olegkon, May 6, 2010.

  1. olegkon

    olegkon Guest

    I need to write a Java program which:
    - collects bunch of data from the SQL Server DB (and builds command
    line);
    - calls windows executable (3rd party, black box, I assume it's
    written with .NET 3.5 - maybe VB or C#, but have no source code or
    anything)
    and passes it long list of parameters.

    My Java program will be packaged as executable JAR and reside on some
    Windows XP server.
    It will be called from job scheduler.
    So basically it will be a Java wrapper for that .NET exec.

    Could anyone help me with a sample skeleton code to call .NET
    executable ?

    Sorry, I have no experience with that, I am more of Java/Flex Web
    developer.

    So suppose I am calling that
    Runtime.getRuntime().exec(new String[] {"prog1" "param1" "param2"});

    Is there any limitation to the size of that parameters line on Windows
    XP ?
    I have to pass a huge parameters list, something over 8Kb.

    Is that possible ?

    If not, how can we overcome it ?

    Any code samples ?

    Please advise,
    Oleg.
    olegkon, May 6, 2010
    #1
    1. Advertising

  2. Thu, 6 May 2010 14:33:02 -0700 (PDT), /olegkon/:

    > I need to write a Java program which:
    > - collects bunch of data from the SQL Server DB (and builds command
    > line);
    > - calls windows executable (3rd party, black box, I assume it's
    > written with .NET 3.5 - maybe VB or C#, but have no source code or
    > anything)
    > and passes it long list of parameters.


    If it is a Windows executable there should be no difference what
    source language was used to compile it.

    > (...)
    > So suppose I am calling that
    > Runtime.getRuntime().exec(new String[] {"prog1" "param1" "param2"});
    >
    > Is there any limitation to the size of that parameters line on Windows
    > XP ?
    > I have to pass a huge parameters list, something over 8Kb.
    >
    > Is that possible ?


    How is this executable currently used? You should have some docs on
    how to use it, right? The Windows CreateProcess [1] function has a
    limitation of 32767 characters for the command-line to be executed,
    so if the JVM implementation uses that you will get that. The
    command processor (cmd.exe) on the other hand has a limitation of
    8191 characters [2] (so you can't test it directly from the command
    shell).

    You could at least check this: create two test classes, the first
    executing the second in a separate java process passing it something
    over 8KB command-line data, then the second one verifying what it
    has got. Haven't you tried it already?

    > If not, how can we overcome it ?


    If one could modify the executable being invoked one could always
    make it read its input from a file, if it is expected to be that big.

    [1] http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx
    [2] http://support.microsoft.com/kb/830473

    --
    Stanimir
    Stanimir Stamenkov, May 6, 2010
    #2
    1. Advertising

  3. olegkon

    Roedy Green Guest

    On Thu, 6 May 2010 14:33:02 -0700 (PDT), olegkon <>
    wrote, quoted or indirectly quoted someone who said :

    >
    >Could anyone help me with a sample skeleton code to call .NET
    >executable ?


    First of all figure out how to call your .net stuff from the "DOS"
    command line. Then see http://mindprod.com/jgloss/exec.html
    to see how to simulate it.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    What is the point of a surveillance camera with insufficient resolution to identify culprits?
    Roedy Green, May 6, 2010
    #3
  4. olegkon

    Arne Vajhøj Guest

    On 06-05-2010 17:33, olegkon wrote:
    > I need to write a Java program which:
    > - collects bunch of data from the SQL Server DB (and builds command
    > line);
    > - calls windows executable (3rd party, black box, I assume it's
    > written with .NET 3.5 - maybe VB or C#, but have no source code or
    > anything)
    > and passes it long list of parameters.
    >
    > My Java program will be packaged as executable JAR and reside on some
    > Windows XP server.
    > It will be called from job scheduler.
    > So basically it will be a Java wrapper for that .NET exec.
    >
    > Could anyone help me with a sample skeleton code to call .NET
    > executable ?
    >
    > Sorry, I have no experience with that, I am more of Java/Flex Web
    > developer.
    >
    > So suppose I am calling that
    > Runtime.getRuntime().exec(new String[] {"prog1" "param1" "param2"});
    >
    > Is there any limitation to the size of that parameters line on Windows
    > XP ?
    > I have to pass a huge parameters list, something over 8Kb.
    >
    > Is that possible ?
    >
    > If not, how can we overcome it ?
    >
    > Any code samples ?


    The code is as it should be.

    (hm - actually you should be using ProcessBuilder instead)

    There does not seem to be any guarantees in the documentation.

    So I think you should test on your platform with your Java version
    what the implementation specific limit happens to be.

    (and cross your fingers that next upgrade does not change the
    limit)

    Arne
    Arne Vajhøj, May 7, 2010
    #4
  5. olegkon

    Wojtek Guest

    olegkon wrote :
    > Is there any limitation to the size of that parameters line on Windows
    > XP


    Instead write out the parameters to a file, pass the file name, and
    have the .NET app read the file.

    --
    Wojtek :)
    Wojtek, May 7, 2010
    #5
    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. Hal Vaughan
    Replies:
    11
    Views:
    1,091
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,064
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    451
    Duncan Booth
    Jul 22, 2004
  4. olegkon

    Java calling .NET exec

    olegkon, Apr 29, 2010, in forum: Java
    Replies:
    3
    Views:
    490
    olegkon
    May 6, 2010
  5. Guillermo Riojas
    Replies:
    0
    Views:
    157
    Guillermo Riojas
    Nov 26, 2010
Loading...

Share This Page