所以我想知道,如何在CMD中使用C#执行多个命令?我的意思是这样的...我有一个.exe文件,它依赖于通过cmd变量(VAMP_PATH)找到文件[是的,我正在使用VAMP插件]。所以,我在CMD使用的方法是:来自C#的多个CMD命令?
-set VAMP_PATH:C:\ (press Enter)
-sonic-annotator.exe -d etc...
不过,我在试图使用CMD与C#相当新的所以我想知道我应该怎么办呢?目前,我有这样的代码:
Process p = new Process();
string args = "\"" + sonicannotatorpath + "\" -t \"" + transpath + "\" \"" + filepath + "\" -w csv --csv-force";
p.StartInfo = new ProcessStartInfo("cmd", args)
{
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p.Start();
p.StandardInput.WriteLine(args);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine("DONE");
Console.Read();
只有上面的代码执行从我的CMD命令第二行......但由于该.exe需要的是已经在其默认位置的文件,没有指定没有问题VAMP_PATH命令。
我的问题是我不知道如何添加另一个命令。我只需要复制p.StandardInput.WriteLine命令并只输入另一个命令作为参数?因为我读到有关于此的一些问题。我想问,因为没有p.StandardInput.WriteLine命令,并且只是在ProcessStartInfo中的'args'参数,我的命令完全不会执行(甚至在将\ c添加到参数时)。你为什么认为这是?
谢谢!
所以它会是这样的:p.StandardInput.WriteLine(); output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); p.StandardInput.WriteLine(); output = p.StandardOutput.ReadToEnd();?对不起,如果有点凌乱 – user488792 2011-05-19 14:24:21