我正在尝试为我的游戏制作启动器,我喜欢在后台添加音乐播放器,但如果我开始这个过程,它会立即失败。
码
private void btnStartMusic_Click(object sender, EventArgs e)
{
ProcessStartInfo proc = new
ProcessStartInfo("MusicPlayer\\MemequickieMusicPlayer.exe");
proc.CreateNoWindow = true;
proc.WindowStyle = ProcessWindowStyle.Hidden;
proc.RedirectStandardError = false;
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = false;
proc.UseShellExecute = false;
Process.Start(proc);
}
任何帮助表示赞赏。
尝试使用exe的完整路径并设置工作目录;假设exe在您的可执行文件夹中:
string path = Path.Combine(Application.StartupPath, "MusicPlayer");
ProcessStartInfo proc = new
ProcessStartInfo(Path.Combine(path, "MemequickieMusicPlayer.exe"));
proc.WorkingDirectory = path;
如果错误仍然存在并且您要调试输出,请更改:
proc.RedirectStandardOutput = true;
创建这样的过程:
Process process = new Process(proc);
process.Start();
while (!process.StandardOutput.EndOfStream) {
System.Diagnostics.Debug.Write(process.StandardOutput.ReadLine());
}
您现在应该在输出窗口中看到输出。