Executing compiled jar file from .NET (System.Diagnostics.Process)

浪子不回头ぞ 提交于 2019-12-12 02:35:47

问题


Trying to integrate the google closure compiler in a batch job of mine and having difficulty getting it to work.

Using command prompt I can enter the following command and get my scripts compiled. (The command is a self explanatory example)

java -jar "compiler.jar" --js_output_file="myOutput.min.js" --js="input1.js" --js="input2.js"

I have tried to replicate this using the System.Diagnostics.Process object but thus far have failed.

I have tried

Dim command As String = BuildCommand(CompilationScripts, Me._Output)
Dim process As New Process
process.Start("compiler.jar", command)

And I have tried

Dim command As String = BuildCommand(CompilationScripts, Me._Output)
Dim process As New Process
process.StartInfo.Arguments = command
process.Start("compiler.jar")

And I have tried

 Dim command As String = BuildCommand(CompilationScripts, Me._Output)
 Dim process As New Process
 process.StartInfo.Arguments = command
 process.Start("cmd.exe")

What am I doing wrong?


回答1:


Arguments should be

-jar "compiler.jar" --js_output_file="myOutput.min.js" --js="input1.js" --js="input2.js"

i.e. no java keyword here.

Also set

process.StartInfo.FileName = "java"

EDIT

process.StartInfo.RedirectStandardInput = True
process.StartInfo.CreateNoWindow = False
process.StartInfo.UseShellExecute = False
process.StartInfo.FileName = "java"


来源:https://stackoverflow.com/questions/4930016/executing-compiled-jar-file-from-net-system-diagnostics-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!