我通过C#代码运行Ubuntu Shell命令,当我在Ubuntu中运行此脚本时,它显示为'语法正常',但是当我通过C#代码运行它时,它总是返回exitCode - 1.如果ID错误,请更正我的代码。
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\"";