【发布时间】:2020-04-16 06:57:22
【问题描述】:
我需要从我的程序中启动一个 java .jar 进程。
一旦开始,我得到输出并处理它。
为此,我使用以下代码:
Dim p_Process As New Process()
Dim p_p As New ProcessStartInfo
p_p.FileName = "java.exe"
p_p.Arguments = "-jar myjar.jar"
p_p.WorkingDirectory = apppath & "\myFolder"
p_p.UseShellExecute = False
p_p.RedirectStandardOutput = True
p_p.WindowStyle = ProcessWindowStyle.Minimized
AddHandler p_Process.OutputDataReceived, AddressOf manageContent
p_Process.StartInfo = p_p
p_Process.Start()
p_Process.BeginOutputReadLine()
我需要以下几行来获取 Process 的输出以供我使用:
p_p.UseShellExecute = False
p_p.RedirectStandardOutput = True
一切正常,但窗口未最小化。
如何最小化窗口?
【问题讨论】:
-
WindowState.Minimized,你确定吗?你有Option Strict On吗?您是否尝试过ProcessWindowStyle.Minimized?还有p_p.UseShellExecute = True?或者也许你想隐藏窗口? -
WindowsStyle属性的文档包含一个代码示例,显示它被设置为ProcessWindowStyle.Minimized,而不是WindowState.Minimized。始终阅读文档。 -
@Jimi,
UseShellExecute的文档说 “如果将WindowStyle设置为ProcessWindowStyle.Hidden,UseShellExecute必须设置为true”,所以在这种情况下没有问题。 -
@jmcilhinney 自我发布该评论以来,该问题已被编辑。最初,OP 忘记提及他们需要使用
RedirectStandardOutput = True。所以我暗示,也许他们可以使用ShellExecute = True来获得最小化(或隐藏)的效果。现在它不再适用了。但无论如何,您都可以将其最小化。 PInvoking,带有 UI 自动化等。 -
@Jimi:对不起,在这里传递代码是一个错误。我使用 ProcessWindowStyle.Minimized。关于 p_p.UseShellExecute,它必须为 false 才能重定向输出。如果设置为 true,则无法重定向。
标签: java .net vb.net jar process