我试图使用System.Diagnostics.Process和System.Diagnostics.ProcessStartInfo通过C#代码启动节点命令,但在我的测试系统上遇到此错误(在开发系统上没有此错误)。
此命令的输出通过管道传输到文本文件,这就是写入错误的地方。
string filename = string.Format("\"{0}\"", nodePath);
string arguments = string.Format("\"{0}\" -u \"{1}\" -p \"{2}\" > \"{3}\"",
scriptPath, uName, pword, outFileName);
ProcessStartInfo si = new ProcessStartInfo
{
FileName = filename,
Arguments = arguments,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
RedirectStandardError = true
};
Process p = new Process
{
StartInfo = si
};
string statusMessage = String.Format("Executing command: '{0}'", si.FileName);
Logger.LogDomInfo(statusMessage);
bool started = p.Start();
正如我之前提到的,这在开发机器上运行得很好,但在测试环境中却失败,并出现以下错误:
ERROR: The process with PID 4880 (child process of PID 5440) could not be terminated.
Reason: There is no running instance of the task.