Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# cmd

string param="java -jar -Xmx4000m train_one.jar class_funnyai.ini 12011 10";
run_cmd(param);

void run_cmd(string param)
{
	var proc = new Process();
	proc.StartInfo.FileName = "cmd.exe";
  
	// set up output redirection
	proc.StartInfo.RedirectStandardInput= true;
	proc.StartInfo.RedirectStandardOutput = true;
	proc.StartInfo.RedirectStandardError = true;
	proc.EnableRaisingEvents = true;
	proc.StartInfo.CreateNoWindow = true;
	proc.StartInfo.StandardOutputEncoding = Encoding.UTF8;

	// see below for output handler
	proc.ErrorDataReceived += callback_data;
	proc.OutputDataReceived += callback_data;

	proc.Start();

	using (StreamWriter sw = proc.StandardInput)
	{
		if (sw.BaseStream.CanWrite)
		{
			sw.WriteLine(param);
		}
	}


	proc.BeginErrorReadLine();
	proc.BeginOutputReadLine();

	proc.WaitForExit();
}

void callback_data(object sender, DataReceivedEventArgs e)
{
	Console.WriteLine(e.Data);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #cmd
ADD COMMENT
Topic
Name
6+3 =