如何在C#中执行ubuntushell命令以将exitCode设置为0

如何在C#中执行ubuntushell命令以将exitCode设置为0,c#,ubuntu,C#,Ubuntu,我通过C代码运行Ubuntu Shell命令,当我在Ubuntu中运行这个脚本时,它显示为“Syntax OK”,但当我通过C代码运行它时,它总是返回exitCode-1。如果有什么错误,请更正我的代码 string _exitCode=""; Process proc = new Process(); proc.StartInfo.FileName = "/bin/bash"; proc.Sta

我通过C代码运行Ubuntu Shell命令,当我在Ubuntu中运行这个脚本时,它显示为“Syntax OK”,但当我通过C代码运行它时,它总是返回exitCode-1。如果有什么错误,请更正我的代码

            string _exitCode="";
            Process proc = new Process();
            proc.StartInfo.FileName = "/bin/bash"; 

            proc.StartInfo.Arguments ="-c \" apachectl -t -f /etc/apache2/sites-enabled/example.conf \""; 

            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;

            proc.Start();

            proc.BeginOutputReadLine();

            proc.StandardError.ReadToEndAsync();

            proc.WaitForExit(3000);

            if (!proc.HasExited)
                proc.Kill();

            _exitCode = proc.ExitCode.ToString();
要更正命令,请执行以下操作:

"-c \"/etc/init.d/apachectl -t -f /etc/apache2/sites-enabled/example.conf 2>&1\"";