gpt4 book ai didi

c# - 从 C# 运行 Jar 文件

转载 作者:行者123 更新时间:2023-12-02 08:26:25 33 4
gpt4 key购买 nike

给定的代码是用于在 C# 环境中运行 jar 文件的代码的一部分。 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,以便在进程启动时触发相应的文件。但上面给出的代码也运行成功。

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

最佳答案

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

当您的路径包含空格时,通常需要这样做。

如果路径包含空格(例如"C:\Program Files"),Windows 要求将路径加引号。

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

在这种情况下,它们似乎是多余的。

关于c# - 从 C# 运行 Jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4427371/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com