C# .NET进程在Windows 8上失败
我在Windows8上运行应用程序时遇到两个奇怪的问题(在Windows7上运行很好) 我正在运行外部“a.exe”应用程序 第一个问题是,当我使用进程运行“a.exe”时,我没有得到任何输出。 如果我运行一个执行“a.exe”的批处理文件并将输出写入一个文件,则会有一个输出 第二个问题是,在这两种情况下(批处理和进程),“a.exe”都失败。但在命令行中它可以工作 代码如下:C# .NET进程在Windows 8上失败,c#,process,windows-8,C#,Process,Windows 8,我在Windows8上运行应用程序时遇到两个奇怪的问题(在Windows7上运行很好) 我正在运行外部“a.exe”应用程序 第一个问题是,当我使用进程运行“a.exe”时,我没有得到任何输出。 如果我运行一个执行“a.exe”的批处理文件并将输出写入一个文件,则会有一个输出 第二个问题是,在这两种情况下(批处理和进程),“a.exe”都失败。但在命令行中它可以工作 代码如下: proc = new Process(); proc.StartInfo.FileName = Path; pr
proc = new Process();
proc.StartInfo.FileName = Path;
proc.StartInfo.Arguments = args;
proc.StartInfo.WorkingDirectory = GetDirectoryName(Path);
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Verb = "runas administrator";
proc.OutputDataReceived += (sendingProcess, line) =>
{
string s = line.Data;
if (!string.IsNullOrWhiteSpace(s))
{
_sbStdout.AppendLine(line.Data);
}
};
proc.ErrorDataReceived += (sendingProcess, line) =>
{
string s = line.Data;
if (!string.IsNullOrWhiteSpace(s))
{
_sbStderr.AppendLine(line.Data);
}
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
// Wait for exit or timeout
bool res = true;
if (timeout <= 0 || timeout == null)
proc.WaitForExit();
else
res = proc.WaitForExit((int)timeout);
ExitCode = proc.ExitCode;
proc=newprocess();
proc.StartInfo.FileName=路径;
proc.StartInfo.Arguments=args;
proc.StartInfo.WorkingDirectory=GetDirectoryName(路径);
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.RedirectStandardError=true;
proc.StartInfo.RedirectStandardOutput=true;
proc.StartInfo.UseShellExecute=false;
proc.StartInfo.Verb=“运行方式管理员”;
proc.OutputDataReceived+=(发送过程,行)=>
{
字符串s=line.Data;
如果(!string.IsNullOrWhiteSpace))
{
_sbStdout.AppendLine(line.Data);
}
};
proc.ErrorDataReceived+=(发送过程,行)=>
{
字符串s=line.Data;
如果(!string.IsNullOrWhiteSpace))
{
_sbStderr.AppendLine(行数据);
}
};
proc.Start();
进程BeginOutputReadLine();
proc.BeginErrorReadLine();
//等待退出或超时
bool res=真;
如果(超时)这不是报告Windows 8错误的正确位置。当前版本只是预览版,不是测试版,因此还没有正式的方法报告错误。您可以在此处找到有关使用Windows反馈工具的提示:args和Path的值是多少?