在 .NET 中的当前命令窗口中启动进程
我在 VB.NET 控制台应用程序中有这个:
Dim p As ProcessStartInfo
p = New ProcessStartInfo(Environment.CurrentDirectory & "\bin\javac.exe",ClassName & ".java")
Dim ps As Process = Process.Start(p)
这确实在文件上运行 java 编译器,但它是在新窗口中运行的。我希望 javac 的输出出现在运行我的应用程序的同一控制台中。 我该怎么做?也许还有另一种方法可以在当前控制台中运行命令?或者也许我可以禁止打开第二个控制台窗口并将其输出重定向到当前控制台?
I have this in a VB.NET console application:
Dim p As ProcessStartInfo
p = New ProcessStartInfo(Environment.CurrentDirectory & "\bin\javac.exe",ClassName & ".java")
Dim ps As Process = Process.Start(p)
This does run the java compiler on the file, but it does so in a new window. I want the output from javac to appear in the same console that is running my application.
How can I do this? Perhaps there is another method for running commands in the current console? Or maybe I can supress the second console window from opening and redirect its output to the current console?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你可以在同一个控制台中运行,但你可以通过重定向标准输出来获取输出:
I don't think you can run in the same console but you can get the output by redirecting the standard out:
我不认为你可以在同一个控制台中运行,因为它被你的应用程序占用。如果只是显示输出,您可以使用 流重定向。如果您执行
javac [here go params] >out.txt 2>err.txt
,您可以稍后在javac
完成时加载它们的输出。您甚至可以通过 ProcessStartInfo.RedirectStandardOutput 将流重定向到您的应用程序 和 Process.StandardOutput
I don't think that you can run in same console, because it is occupied by your application. If it is just about showing output you can use stream redirection. If you do
javac [here go params] >out.txt 2>err.txt
you can later load outputs from them whenjavac
finished.You can even redirect streams to your application by ProcessStartInfo.RedirectStandardOutput and Process.StandardOutput