从C#运行Jar文件 [英] Run Jar file from C#

查看:616
本文介绍了从C#运行Jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出的代码是用于在c#环境中运行jar文件的代码的一部分. 完整代码

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;

我知道processJar.StartInfo.FileName应该包含jave.exe,以便在进程启动时将触发相应的文件.但是上面给出的代码也可以成功运行.

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.

问题: "\""+ @" java"+" \" 在这里是什么?如果我提供这样的输入,系统本身将搜索java.exe吗?

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

推荐答案

它们只是确保字符串为"java"(带引号).

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包含空格(例如"C:\Program Files"),则要求该路径加引号.

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

关于查找可执行文件-如果java可执行文件的路径在%PATH%环境变量中,则会找到它.

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.

这篇关于从C#运行Jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆