Capture output
-
I launch a dos program inside my program and then capture the command line output to my VB program. How to do this? Thanks!
When you shell out to your DOS application, pipe the output to a file using the '>' directive, then reed the file in after the program is done.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."
-
When you shell out to your DOS application, pipe the output to a file using the '>' directive, then reed the file in after the program is done.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."
This is a very inefficient way to do this and will only return the complete result after the program has finished executing. :~ Providing you've left the caves and moved into .NET, the more efficient way is to:
Dim myProc As New System.Diagnostics.Process myProc.StartInfo.UseShellExecute = False myProc.StartInfo.RedirectStandardOutput = True myProc.StartInfo.FileName = "ping" myProc.StartInfo.Arguments = "www.google.com" myProc.Start()
You have now taken control of the process and have access to the output AND input streams. You could even write your own version of command.com if you wanted. :) The output stream is located at:myProc.StandardOutput
Im sure you'll find the rest. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989 -
This is a very inefficient way to do this and will only return the complete result after the program has finished executing. :~ Providing you've left the caves and moved into .NET, the more efficient way is to:
Dim myProc As New System.Diagnostics.Process myProc.StartInfo.UseShellExecute = False myProc.StartInfo.RedirectStandardOutput = True myProc.StartInfo.FileName = "ping" myProc.StartInfo.Arguments = "www.google.com" myProc.Start()
You have now taken control of the process and have access to the output AND input streams. You could even write your own version of command.com if you wanted. :) The output stream is located at:myProc.StandardOutput
Im sure you'll find the rest. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989Well that seems very elegant. I have to admit that I was unaware of how to do that. It does only work for VB.NET however. I am not sure what Teir was working in (.NET or VB6). Thanks.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."
-
Well that seems very elegant. I have to admit that I was unaware of how to do that. It does only work for VB.NET however. I am not sure what Teir was working in (.NET or VB6). Thanks.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things."
I have implemented this code in a WebForm which basically gives me a remote command line into the server. I never thought I would tunnel DOS over the internet. This does make a few holes in the security of shared hosting as it effectively bypasses all permissions. While you may not by able to use System.IO to delete say C:\Autoexec.bat - you can upload a console app and execute that from the machines system account. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989