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.

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

this line is probably the error

proc.StartInfo.Arguments = "-cp " + strJarFilePath + "ipc.IPC -c C400Cl400 -t > ccl4.rtf";

notice that there is no space between the path and the "ipc.IPC" string.

I'd recommend, instead of doing that kind of concatenation, using string format, it's much clearer and easier to see.

proc.StartInfo.Arguments = string.Format("-cp {0} ipc.IPC -c C400C1400 -t > cc14.rtf", strJarFilePath);

Hi,

Thanks for the reply. I got the result but the redirection into a text file is not working. Is there any other hint that I can redirect the result into a text file.

Thanks,
Srikanth

this line is probably the error

proc.StartInfo.Arguments = "-cp " + strJarFilePath + "ipc.IPC -c C400Cl400 -t > ccl4.rtf";

notice that there is no space between the path and the "ipc.IPC" string.

I'd recommend, instead of doing that kind of concatenation, using string format, it's much clearer and easier to see.

proc.StartInfo.Arguments = string.Format("-cp {0} ipc.IPC -c C400C1400 -t > cc14.rtf", strJarFilePath);

If you have the result but it's not saving, that means that the error is in your java code. Since your passing the path to save to rtf as an argument to your jar file. Unless it's your argument line.

Do you agree with me?

Hi,

I'm sorry for being unclear. Actually the problem has been rectified just now. It is redirecting the stdio into a file. Now it is working by using steamreader.

Thanks for the support.

If you have the result but it's not saving, that means that the error is in your java code. Since your passing the path to save to rtf as an argument to your jar file. Unless it's your argument line.

Do you agree with me?

This make sens ^^.

No problem.

Mark the topic as solved if you are satisfied ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.