0

I have .jar to execute from windows from, so far I was able to lunch the program from my window form, but when I put information in my java file I get no result the java file does nothing. If I go manualy double click and execute the .jar file and put the information I get the resul.

here is my code to execute java inside windows form :

 Process p = Process.Start(@"C:\convert\Convert.jar");
            Thread.Sleep(500);
            p.WaitForInputIdle();
            SetParent(p.MainWindowHandle, this.Handle);

.jar file is for to convert .csv to .txt with special data.

nater303
  • 85
  • 2
  • 14
  • 2
    `java -jar C:\convert\Convert.jar` – libertylocked Mar 18 '16 at 14:44
  • Thanks Liberty but it is not working I have tried this before. – nater303 Mar 18 '16 at 14:47
  • @nater303 what exactly happens when you run LibertyLocked's suggestion? It's definitely more correct than the original attempt. For testing purposes: try running ``java -version``. – f1sh Mar 18 '16 at 14:49
  • I can execute the .jar file but no result for my conversion. – nater303 Mar 18 '16 at 14:51
  • And for java version : java version "1.8.0_73" Java(TM) SE Runtime Environment (build 1.8.0_73-b02) Java HotSpot(TM) Client VM (build 25.73-b02, mixed mode, sharing) NOTE: csv.csv it is in the same folder as Convert.jar – nater303 Mar 18 '16 at 14:56
  • 1
    @nater303 Have you tried setting working directory to C:\convert? http://stackoverflow.com/questions/114928/net-process-start-default-directory – libertylocked Mar 18 '16 at 15:02
  • BINGO! It woks, I had to set up the working directory because the .jar looks for files in the same folder where it is. Thanks Liberty Locked for the link. – nater303 Mar 18 '16 at 15:24

2 Answers2

0

To run a jar, you need to use

java -jar <FILENAME.jar>

In your case it would be

Process p = Process.Start(@"java -jar C:\convert\Convert.jar");
        Thread.Sleep(500);
        p.WaitForInputIdle();
        SetParent(p.MainWindowHandle, this.Handle);
libertylocked
  • 892
  • 5
  • 15
0

Here is the solution :

System.Diagnostics; ... ProcessStartInfo _processStartInfo = new ProcessStartInfo();
_processStartInfo.WorkingDirectory = @"%ProgramFiles%";
_processStartInfo.FileName = @"Notepad.exe"; 
_processStartInfo.Arguments = "test.txt"; 
_processStartInfo.CreateNoWindow = true;
Process myProcess = Process.Start(_processStartInfo); 
emartinelli
  • 1,019
  • 15
  • 28
nater303
  • 85
  • 2
  • 14