calling jar file in c#

Discussion in 'C#' started by srikanth2321, Aug 28, 2010.

  1. srikanth2321

    srikanth2321 Guest

    Hi,

    I have a software which contains a jar file. To use it I need to type "java -cp IPC.jar ipc.IPC -c CCl4 -t > CCl4.txt" in the command line. I want to invoke this in C#.



    I used this following code but it is doing nothing, no errors.



    Code:
      
    using System;
    
    using System.Collections.Generic;
    
    using System.ComponentModel;
    
    using System.Data;
    
    using System.Drawing;
    
    using System.Linq;
    
    using System.Text;
    
    using System.Windows.Forms;
    
    using System.Diagnostics;
    
    using System.IO;
    
    
    
    
    
    namespace WindowsFormsApplication7
    
    {
    
     public partial class Form1 : Form
    
     {
    
      public Form1()
    
      {
    
       InitializeComponent();
    
      }
    
    
    
      private void Form1_Load(object sender, EventArgs e)
    
      {
    
       String strJarFilePath = "D:\\Downloads\\IPC_Program\\IPC.jar";
    
    
    
       Process proc = new Process();
    
       try
    
       {
    
        proc.StartInfo.FileName = "java";
    
        proc.StartInfo.Arguments = "-cp " + strJarFilePath + "ipc.IPC -c C400Cl400 -t > ccl4.rtf";
    
        proc.StartInfo.CreateNoWindow = false;
    
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    
        proc.StartInfo.UseShellExecute = false;
    
    
    
        DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
    
        proc.StartInfo.WorkingDirectory = currentDir.FullName;
    
    
    
        proc.Start();
    
        
    
        proc.WaitForExit(5000);
    
        
    
       }
    
       catch (Exception ex)
    
       {
    
        if (!proc.Start())
    
         throw new Exception("Failed to start Pull process");
    
    
    
       }
    
      }
    
     }
    
    }
    At the end it should write the result (displayed in the command line) in a text file.





    thanks,

    Srikanth
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice