简体   繁体   English

命令行过程

[英]Command Line Process

So after scouring the web I found a few articles (some on stackoverflow) which described how to execute a command line prompt by starting a new process in c#. 因此,在浏览Web之后,我发现了几篇文章(有些是关于stackoverflow的),描述了如何通过在c#中启动新进程来执行命令行提示符。 The second argument, which I've commented out, works just fine, but the one I actually need (the first one) doesn't. 我已经注释掉的第二个参数很好用,但是我实际需要的参数(第一个)却无效。 It returns the error "Could not find or load main class edu.stanford.nlp.parser.lexparser.LexicalizedParser" When I open up a command line (non-programatically) and then execute the same command (aside from the escaped quotations) it works great. 它返回错误“找不到或加载主类edu.stanford.nlp.parser.lexparser.LexicalizedParser”错误。当我打开一个命令行(非编程方式)然后执行相同的命令(除了转义的引号之外)时,它效果很好。 Any idea's about what the problem could be? 关于可能的问题有什么想法? Thanks! 谢谢!

var proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = "CMD.exe",
        Arguments = "/c java -mx100m -cp \"*\" edu.stanford.nlp.parser.lexparser.LexicalizedParser edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz libtest.txt",
        // Arguments = "/c echo Foo", 
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true
    }
};
proc.Start();

Console.WriteLine(proc.StandardOutput.ReadToEnd());
Console.WriteLine(proc.StandardError.ReadToEnd());

Ensure that the executing path where you start your process is correct! 确保您开始过程的执行路径正确!

You can use Process Monitor from SysInternals to figure out where that class is looked for. 您可以使用SysInternals中的Process Monitor来查找该类的位置。

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

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