开发者

Multiple CMD Commands from C#?

So I'm wondering, how do I execute multiple commands in CMD using C#? What I mean is this ... I have a .exe file that relies on finding the files via a cmd variable (VAMP_PATH) [yes I am using VAMP Plugin]. So the way I use this in CMD would be:

-set VAMP_PATH:C:\ (press Enter)
-sonic-annotator.exe -d etc...

However, I am fairly new in trying to use CMD with C# so I am wondering what I should do? Currently I have this code:

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(); 

The code above only performs the second line from my CMD command ... but since the files the .exe need is already in its default location, there is no problem not specifying the VAMP_PATH command.

My problem is I am not sure how to add another command. Would I simply just need to copy the p.开发者_JAVA百科StandardInput.WriteLine command and just input another command as a parameter? Because I read that there are some problems regarding this.

Additionally, I would like to ask because without the p.StandardInput.WriteLine command, and just with the 'args' parameter in ProcessStartInfo, my command does not execute at all (even with the \c added to args). Why do you think this is?

Thanks!


You can't run two commands (effectively two processes) from one process object, without first letting the first process complete.

Run the first one, call p.WaitForExit(); and then build and run the second.

For starting the process you shouldn't need to write the Arguments to the command line the way you currently are doing it. It should work the way that you are doing it.

p.StartInfo.Arguments = args;
p.StartInfo.FileName = "cmd";

May work for you for setting up the Arguments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜