VB.NET - How to capture execution output using Shell()?

Asked By Jack Bishop
31-Aug-04 05:49 PM
Howdy,

I'm trying to capture the output of a command invoked with Shell(). For example, 

Shell("dir c:\", vbMinimizedNoFocus) or, more helpful,

Shell("telnet baz", vbMinimizedNoFocus).

I've attempted playing some redirection games with the local DOS command thinking I can work around some of the resulting limitations but no go. I'm trying to invoke a command on a *nix server and capture its output for further analysis/ investigation. I can invoke a dos command (ergo the "dir c:\" example) to accomplish my goal.

TIA for suggestions and guidance.

Better to use the Process class  Better to use the Process class

31-Aug-04 06:49 PM
with the StartInfo methods, than to use the VB.NET "Crutch" classes from the VisualBasic namespaces:

Example (untested code, but you get the idea):

Process process = new Process();
    string FileName="telnet";
    string Arguments = "baz";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.FileName = FileName;
    process.StartInfo.Arguments = Arguments;
    process.StartInfo.WorkingDirectory = WorkingDirectory;
    process.Start(); 
    string output = process.StandardOutput.ReadToEnd();

VB.NET:
Dim process As New Process()
Dim FileName As String = "telnet"
Dim Arguments As String = "baz"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.StartInfo.FileName = FileName
process.StartInfo.Arguments = Arguments
process.StartInfo.WorkingDirectory = WorkingDirectory
process.Start()
Dim output As String = process.StandardOutput.ReadToEnd()
Create New Account
help
types? (B) What is concept of Boxing and Unboxing ? (B) What is the difference between VB.NET and C#? (I) what is the difference between System exceptions and Application exceptions? (I)What How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote Cache substitution? Chapter 6: OOPS (B) What is Object Oriented Programming? (B) What is a Class? (B) What is an Object? (A) What is the relation between Classes and Objects? (B are different properties provided by Object-oriented systems? (B) How can we achieve inheritance in VB.NET? (I) what are abstract classes? (B) What is a Interface? (A) What is difference between Overriding? (I) what is the difference between delegate and events? (B) If we inherit a class do the private variables also get inherited? (B) What is the different accessibility levels defined
Interface and Abstract Class Hai, When do we go for Interface. . When do we go for Abstract Class. . .Give one example Today i faced one interview . . He asked this question.I want answer with Example Thanks in Advance Abstract Class :: - It cannot defines all the methods - It has subclass. - Here, Subclass is useless - A class can be extend an abstract class Interface :: - It defines all the methods - It must have implementations by other classes, But there http: / / kyapoocha.com / c-sharp-interview-questions / what%E2%80%99s-the-difference-between-an-interface-and-abstract-class-5 / http: / / www.dotnetuncle.com / Difference / 4_abstract_class_interface.aspx Hope this helps. HI An interface contains signatures of methods , delegates or events . The implementation of the methods is done in the class that implements the interface, as shown in the following example: interface ISampleInterface { void SampleMethod(); } class ImplementationClass : ISampleInterface { / / Explicit interface member implementation: void ISampleInterface.SampleMethod() { / / Method implementation. } static void Main() { / / Declare
Difference between vb and vb.net Hai, I want to know about the main difference between vb and vb.net. • The greatest change in VB6 and VB.NET is of runtime environment. VB6 used the VB-Runtime while VB.NET uses the .Net Common Language Runtime (.Net CLR). The CLR is much better designed and
Differences for vb.net and c# with Example Dear all Differences for vb.net and c# with Example., plz give the solutions Thanks to all Hi See the bellow comparission :: This comparission is with syntax and example. . . Comments VB.NET 'Single line only Rem Single line only C# / / Single line / * Multiple line * / / / / XML comments on single line / * * XML comments on multiple lines * / Program Structure VB.NET Imports System Namespace MyNameSpace Class HelloWorld 'Entry point which delegates to C-style main Private
diffrence what 's diif b / w vb.net & c#.net refer the link, it explan u Syntax Differences and Managed and Unmanaged code Although there are differences between Visual Basic .NET and Visual C# .NET, both are first-class programming languages that are based on the Microsoft .NET Framework, and they are equally powerful in earlier versions. You have lot of articles to find out the differences b / w VB.NET & C#.NET depending on various aspects. Iam providing a few, which were discussed in different aspects. Go through them. http: / / support.microsoft.com / kb / 308470 some key syntactical differences between VB.NET (version 2) and C#. http: / / www.harding.edu / fmccown / vbnet_csharp_comparison.html Choosing between C# and VB.NET: http: / / www.dnjonline.com / article.aspx?ID = mar05_vbvscsharp Complete Comparison for VB.NET and