Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:20:02+00:00 2026-05-26T07:20:02+00:00

I need to execute commandpromt process async and get the output of the execution.

  • 0

I need to execute commandpromt process async and get the output of the execution. i currently have this code

Public Function ExecuteCommandSync(ByVal command As Object) As String
    Dim result As String = Nothing
    Try
        Dim procStartInfo As New System.Diagnostics.ProcessStartInfo("cmd", "/c " & Convert.ToString(command))
        procStartInfo.RedirectStandardOutput = True
        procStartInfo.UseShellExecute = False
        procStartInfo.CreateNoWindow = True
        Dim proc As New System.Diagnostics.Process()
        proc.StartInfo = procStartInfo
        proc.Start()
        result = proc.StandardOutput.ReadToEnd()
        Console.WriteLine(result)
    Catch objException As Exception
    End Try
    Return result
End Function

Please help me on converting this to async without using a thread. it this possible?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:20:02+00:00Added an answer on May 26, 2026 at 7:20 am

    Below is a class that achieves I believe what you are looking for.

    The process is already running async, I believe what you are looking for is event driven and hidden.
    Do you specifically want a blocking call for some reason, or scared of the threading?

    If I am off base and you want it to block, let me know we can do that too, I cannot imagine why though.

    It essentially allows you to create a cmd shell and interact with it invisibly.

    #Region " Imports "
    
    Imports System.Threading
    Imports System.ComponentModel
    
    #End Region
    
    Namespace Common
    
        Public Class CmdShell
    
    #Region " Variables "
    
            Private WithEvents ShellProcess As Process
    
    #End Region
    
    #Region " Events "
    
            ''' <summary>
            ''' Event indicating an asyc read of the command process's StdOut pipe has occured.
            ''' </summary>
            Public Event DataReceived As EventHandler(Of CmdShellDataReceivedEventArgs)
    
    #End Region
    
    #Region " Public Methods "
    
            Public Sub New()
                ThreadPool.QueueUserWorkItem(AddressOf ShellLoop, Nothing)
                Do Until Not ShellProcess Is Nothing : Loop
            End Sub
    
            ''' <param name="Value">String value to write to the StdIn pipe of the command process, (CRLF not required).</param>
            Public Sub Write(ByVal value As String)
                ShellProcess.StandardInput.WriteLine(value)
            End Sub
    
    #End Region
    
    #Region " Private Methods "
    
            Private Sub ShellLoop(ByVal state As Object)
                Try
                    Dim SI As New ProcessStartInfo("cmd.exe")
                    With SI
                        .Arguments = "/k"
                        .RedirectStandardInput = True
                        .RedirectStandardOutput = True
                        .RedirectStandardError = True
                        .UseShellExecute = False
                        .CreateNoWindow = True
                        .WorkingDirectory = Environ("windir")
                    End With
                    Try
                        ShellProcess = Process.Start(SI)
                        With ShellProcess
                            .BeginOutputReadLine()
                            .BeginErrorReadLine()
                            .WaitForExit()
                        End With
                    Catch ex As Exception
                        With ex
                            Trace.WriteLine(.Message)
                            Trace.WriteLine(.Source)
                            Trace.WriteLine(.StackTrace)
                        End With
                    End Try
                Catch ex As Exception
                    With ex
                        Trace.WriteLine(.Message)
                        Trace.WriteLine(.Source)
                        Trace.WriteLine(.StackTrace)
                    End With
                End Try
            End Sub
    
            Private Sub ShellProcess_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles ShellProcess.ErrorDataReceived
                If Not e.Data Is Nothing Then RaiseEvent DataReceived(Me, New CmdShellDataReceivedEventArgs(e.Data))
            End Sub
    
            Private Sub ShellProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles ShellProcess.OutputDataReceived
                If Not e.Data Is Nothing Then RaiseEvent DataReceived(Me, New CmdShellDataReceivedEventArgs(e.Data & Environment.NewLine))
            End Sub
    
    #End Region
    
        End Class
    
        <EditorBrowsable(EditorBrowsableState.Never)> _
           Public Class CmdShellDataReceivedEventArgs : Inherits EventArgs
            Private _Value As String
    
            Public Sub New(ByVal value As String)
                _Value = value
            End Sub
    
            Public ReadOnly Property Value() As String
                Get
                    Return _Value
                End Get
            End Property
    
        End Class
    
    End Namespace
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need execute some code before Windows shutdown process each time. So, I want
I need to execute some custom code before IControllerFactory.GetControllerInstance() is called. I have looked
I need to execute this python script: http://superjared.com/static/code/googleMX.py I installed pyactiveresource, but when I
I need to execute some JavaScript code when the page has fully loaded. This
I have a Maven project within which I need execute two code generation steps.
I need to execute a custom code function when the report first loads, and
I need to execute code from my python script and take interpreter-style output like
I need to execute code in a class definition in C++. I have a
I need to execute MDX query from command line (MS AS 2005). I have
I need execute an update statement over an sql server table. This table is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.