I have a requirement to execute a .jar
file in another directory. Following is the code I attempted to perform this task,
try
{
Process p = new Process();
p.StartInfo.FileName = @"java cp D:\nfc\nfctools-examples-M9\nfctools-examples-M9\src\main\java\nfctools-examples.jar";//, @"-cp nfctools-examples.jar org.nfctools.examples.hce.HceDemo");
p.StartInfo.Arguments = @"org.nfctools.examples.hce.HceDemo";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
String s = p.StandardOutput.ReadToEnd();
p.WaitForExit();
textBox1.Text = textBox1.Text + "data = " + s;
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
But I get the error The system cannot find the file specified error
. I did the task referring to the posts,
- Starting a Jar file using System.Diagnostics.Process
- Execute Jar file from C sharp code and get return value
I would be really grateful if you experts could assist me in fixing this error. Thank you very much :)
Edit
the path org.nfctools.examples.hce.HceDemo
is in D:\nfc\nfctools-examples-M9\nfctools-examples-M9\src\main\java\
.
The folder stucture is,
D:\
nfc\
nfctools-examples-M9\
nfctools-examples-M9\
src\
main\
java\
*nfctools-examples.jar
|org\
| nfctools\
| examples\
| hce\
| HceDemo.java
The * represents the .jar file that needs to be executed and the pipe symbol represents the class path cp
shown by org.nfctools.examples.hce.HceDemo
.
This execution is done in command prompt via java -cp nfctools-examples.jar org.nfctools.examples.hce.HceDemo
from within the D:\nfc\nfctools-examples-M9\nfctools-examples-M9\src\main\java\
folder.
My requirement is to perform the execution via C#
and obtain the result of the jar
file execution to a textbox
.