启动一个单独的进程,而不将其输出打印到控制台并在程序结束时终止它
我有以下 .NET (Core) 6 代码来打开 Windows 中 VS Code 中的文件夹(我的应用程序不需要在其他环境中运行):
public void OpenInVsCode()
{
Console.WriteLine("Opening folder in VS Code: " + this.Folder);
var procInfo = new ProcessStartInfo("code.exe", this.Folder)
{
// These 3 lines don't seem to matter
RedirectStandardOutput = false,
RedirectStandardInput = false,
RedirectStandardError = false,
// This line should solve the problem but it doesn't
UseShellExecute = true,
};
Process.Start(procInfo);
}
VS Code 确实启动了。但是,它开始将其输出打印到我的控制台应用程序中,当我的控制台应用程序关闭时,VS Code 也会关闭,这似乎与 这个答案相矛盾。
我如何启动一个完全独立的流程?
更新:这似乎很奇怪,在我的控制台应用程序中,如果它自行结束(即到达最后一行),即使我关闭完成的控制台窗口,应用程序也会停止并且不会关闭 VS Code。但是,如果应用程序保持打开状态(由于 Console.ReadLine
或 await Task.Delay
),并且我通过关闭控制台窗口或按 Ctrl + C 来关闭它,则 VS Code 会终止。
I have the following .NET (Core) 6 code to open a folder in VS Code in Windows (my app doesn't need to run on other environments):
public void OpenInVsCode()
{
Console.WriteLine("Opening folder in VS Code: " + this.Folder);
var procInfo = new ProcessStartInfo("code.exe", this.Folder)
{
// These 3 lines don't seem to matter
RedirectStandardOutput = false,
RedirectStandardInput = false,
RedirectStandardError = false,
// This line should solve the problem but it doesn't
UseShellExecute = true,
};
Process.Start(procInfo);
}
VS Code does start. However it starts printing its output into my console app and when my Console app closes, VS Code is closed as well, which seems contradicting to this answer.
How do I start a totally separated Process?
Update: It seems strange that in my Console app if it ends by itself (i.e. reaches to the last line), the app stops and will not close VS Code even if I close the finished Console window. However if the app stays open (due to Console.ReadLine
or await Task.Delay
) and I close it by closing the Console window or pressing Ctrl + C, VS Code is terminated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论