简体   繁体   English

将用于Java的Java命令批处理转换为C#

[英]Translating a batch with java commands for xml to C#

I currently have a batch file with this line: 我目前有一个带有此行的批处理文件:

"C:\Program Files (x86)\Java\jre7\bin\java" -Xmx1224m -classpath .\xalan.jar 
org.apache.xalan.xslt.Process -IN  FileIn.xml -XSL FileConvert.xslt -OUT FileOut.xml

It takes an given xml and a given xslt and spits out a new, converted xml . 它采用给定的xml和给定的xslt并吐出新的,已转换的xml The batch runs just fine, but I'm trying to translate this into C# so that I can build an application around it and have the ability to change some parameters, like which input files to select. 批处理运行得很好,但是我试图将其转换为C#以便我可以围绕它构建一个应用程序,并能够更改某些参数,例如选择哪些输入文件。

My code is this, 我的代码是这样的

ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", 
        "/k " + "\"C:\\Program Files (x86)\\Java\\jre7\\bin\\java\" -Xmx1224m -classpath .\xalan.jar org.apache.xalan.xslt.Process -IN  In.xml -XSL Convert.xslt -OUT Out.xml");
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();

thinking it would run like a simple CMD command. 认为它会像一个简单的CMD命令一样运行。 When I do this, I just get a message with a list of the Java commands you are allowed to use and it quits out there. 当我这样做时,我只会收到一条消息,其中包含允许您使用的Java命令列表,并且在那里退出。 I've tried a few variations of using the quotations, like @"C:\\... and so forth. 我已经尝试了一些使用引号的变体,例如@"C:\\...等。

Any ideas? 有任何想法吗?

Try like below, It will be help you... 尝试如下,它将为您提供帮助...

string commandLine = "-Xmx1224m -classpath .\xalan.jar org.apache.xalan.xslt.Process -IN  In.xml -XSL Convert.xslt -OUT Out.xml";
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(commandLine);
procStartInfo.WorkingDirectory = @"C:\Program Files (x86)\Java\jre7\bin\java";
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
Console.WriteLine(result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM