代码如下
p.StartInfo = new System.Diagnostics.ProcessStartInfo(path, pwd);
p.Start();
其中path是个BAT的路径!
我想要得到执行后的返回值来判断批处理运行期间是否错误?
请问如何做呢?
批处理程序内容如下:
@echo off
for /f "delims=" %%a in (PCList.config) do net use \\%%a\ipc$ /delete
for /f "delims=" %%a in (PCList.config) do net use \\%%a\ipc$ %1 /user:administrator
pause
// Define the namespaces used by this sample.
using System;
using System.Text;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
namespace ProcessAsyncStreamSamples
{
class ProcessNetStreamRedirection
{
// Define static variables shared by class methods.
private static StreamWriter streamError =null;
private static String netErrorFile = "";
private static StringBuilder netOutput = null;
private static bool errorRedirect = false;
private static bool errorsWritten = false;
public static void RedirectNetCommandStreams()
{
String netArguments;
Process netProcess;
// Get the input computer name.
Console.WriteLine("Enter the computer name for the net view command:");
netArguments = Console.ReadLine().ToUpper(CultureInfo.InvariantCulture);
if (String.IsNullOrEmpty(netArguments))
{
// Default to the help command if there is not an input argument.
netArguments = "/?";
}
// Check if errors should be redirected to a file.
errorsWritten = false;
Console.WriteLine("Enter a fully qualified path to an error log file");
Console.WriteLine(" or just press Enter to write errors to console:");
netErrorFile = Console.ReadLine().ToUpper(CultureInfo.InvariantCulture);