开发者

Run Jar file from C#

Given code was a part of the code used to run a jar file on c# environment. Complete Code

strArguments = " -jar "+ Argument list;          
processJar.StartInfo.FileName = "\"" + @"java" + "\"";
processJar.StartInfo.Arguments = strArguments;
processJar.StartInfo.WorkingDirectory =; \\Give the working directory of the application;
processJar.StartInfo.UseShellExecute = false;
processJar.StartInfo.RedirectStandardOutput = true;

I know that processJar.StartInfo.FileName should contain the jave.exe so that the respective file will be triggered when the process gets started. But the above given code also runs successfully.

开发者_Go百科

Question: What does "\"" + @"java" + "\"" here? If I provide such input will the system itself will search java.exe?


They simply ensure that the string will be "java" (with the quotes).

This is normally needed when you have a path that contains spaces.

Windows requires the path to be quoted if it contains spaces (for example "C:\Program Files").

As for finding the executable - if the path to the java executable is in the %PATH% environment variable, it will be found.

In this case they seem superfluous.


its the exe name which needs to be launched

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜