Visual Basic (Visual Studio 2005) 将输入流重定向到进程
我已经在网上搜索了大约三个小时,现在还没有进展。我不太了解 VB,但我需要为任何可执行文件创建一个包装程序来记录参数、所有输入、输出和错误信息:
- 我的包装程序被称为: 例如 someApp.exe arg1 arg2
- 记录到 someApp.log: arg1 arg2
- 调用原始可执行文件: _someApp.exe arg1 arg2
- 必须记录任何控制台输入并将其转发到 _someApp 进程输入流
- 必须记录来自 _someApp 进程的任何输出和错误流
好吧,我现在陷入了第 4 点:
Dim p As New ProcessStartInfo
p.FileName = execute
p.Arguments = Command()
p.UseShellExecute = False
p.CreateNoWindow = True
p.RedirectStandardInput = True
p.RedirectStandardError = True
p.RedirectStandardOutput = True
Dim process As System.Diagnostics.Process
process = Diagnostics.Process.Start(p)
process.WaitForExit()
_someApp 结束后我能够read out 和 err 流来记录它,但我仍然需要向进程提供我自己的包装器输入,并且我想在发生时读取和 err 流。
感谢您提供信息/示例
I've been searching around the net for roughly three hours now w/o getting forward. I don't know VB very well, but I need to create a wrapper program for any executable that logs the arguments, all input, output and err information:
- My wrapper is called: e.g. someApp.exe arg1 arg2
- Logs to someApp.log: arg1 arg2
- Calls original executable: _someApp.exe arg1 arg2
- Must log and forward any console input to _someApp process inputstream
- Must log any output and error stream from _someApp process
Okay, I'm stuck at point 4 now:
Dim p As New ProcessStartInfo
p.FileName = execute
p.Arguments = Command()
p.UseShellExecute = False
p.CreateNoWindow = True
p.RedirectStandardInput = True
p.RedirectStandardError = True
p.RedirectStandardOutput = True
Dim process As System.Diagnostics.Process
process = Diagnostics.Process.Start(p)
process.WaitForExit()
After _someApp ends I am able to read out and err stream to log it, but I still need to provide my own wrappers input to the process and I want to read out and err stream as it happens.
Thanks for info/examples
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这里是解决方案...
所需的变量:
所需的子程序:
在 main 中:
log 是另一个要记录到文件的子程序,execute 是保存我最初帖子中的 _someApp.exe 的变量。我仍然不知道输入流线程的控制台是否正确,因为我的包装应用程序看起来没有输入。可能有人发现错误...
就我的目的而言,嗯,它的工作原理就像我需要它一样
Greetz,
GHad代码
main 内的
Okay here the solution...
Variables needed:
Subs needed:
Inside main:
log is another sub to log to file, execute is the variable holding the _someApp.exe frommy initial post. I still don't know if the console to inputstream thread dows it right, because my wrapped app had no input as it seems. May someone spotts an error...
For my purposes, hmm it works like I need it
Greetz,
GHad
Code inside main
写入应用程序怎么样:
以及从标准输出读取:
How about for writing to the app:
and for reading from the standard output: