简体   繁体   中英

Execute .jar from windows form C#

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.

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);

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM