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 5973401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:47:42+00:00 2026-05-22T20:47:42+00:00

I am running some commands on computers and I would like to have them

  • 0

I am running some commands on computers and I would like to have them output a seperate text file if the command cannot run.

For Each strUserName As String In strLines
        Dim ReplaceCommand As String = sCommand.Replace("*", strUserName).Replace("$$$", saveFileDialog3.FileName & ".txt").Replace("###", exeSearch)
        Shell("cmd.exe /c" & ReplaceCommand, AppWinStyle.Hide, True, )


        ' If Command Cannot Execute, List Why and Move onto Next Command
            Using swrr As New StreamWriter(File.Open(ErrorLog, FileMode.OpenOrCreate))
                If Console.Readline = "blahblah" Then swrr.WriteLine("FAIL") Else swrr.WriteLine("PASS")
        End Using
Next

Am I on the right track? I am getting an output to a text file but its just one line ans always says PASS.

  • 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-22T20:47:43+00:00Added an answer on May 22, 2026 at 8:47 pm

    Several things: you’re creating a new StreamWriter every time you want to write a line to it, instead of creating one then just writing to it when you need to. You’re still using shell which is really basic, and not really suited for what you need. You should really be using a process for this.

    I’ve written a function for you to use to execute the process instead of using the shell, which will return the output from the command execution to the ConsoleOutput variable, which you can then check for output strings.

    Lastly, you should be using String.Format instead of replace to create the correct string for the command to run. For example:

        Dim FirstName As String = "Jay"
        Dim Age As String = "twenty"
        Dim Greeting As String = String.Format("Hello {0}, I know you're {1} years old", FirstName, Age)
        ' Greetings value would be "Hello Jay, I know you're twenty years old"
    

    So tweak the below to suit, specifically the Args variable, USING THE STRING.FORMAT function 🙂

     Sub DoWork()
    
            Dim ConsoleOutput As String = String.Empty
    
            Using swrr As New StreamWriter(ErrorLog, True)
    
                For Each strUserName As String In StrLines
    
                    ConsoleOutput = GetCMDOuput(strUserName, saveFileDialog3.FileName, exeSearch)
    
                    ' If Command Cannot Execute, List Why and Move onto Next Command
                    If ConsoleOutput = "blahblah" Then swrr.WriteLine("FAIL") Else swrr.WriteLine("PASS")
    
                Next
    
            End Using
    
        End Sub
    
        Function GetCMDOuput(ByVal strUserName As String, ByVal strFileName As String, ByVal strExeSearch As String) As String
    
            Dim Args As String = String.Format("/c -paramzero {0} -paramone {1} -paramtwo {2}", strUserName, strFileName, strExeSearch)
    
            Dim CMD As New Process
            CMD.StartInfo.FileName = "cmd.exe"
            CMD.StartInfo.Arguments = Args
            CMD.StartInfo.UseShellExecute = False
            CMD.StartInfo.RedirectStandardInput = True
            CMD.StartInfo.RedirectStandardOutput = True
            CMD.StartInfo.CreateNoWindow = True
            CMD.Start()
    
            Dim retval As String = CMD.StandardOutput.ReadToEnd
    
            CMD.WaitForExit()
    
            Return retval
    
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have a BASH script running some commands in the background. At some
I would like to echo text and also remotely ping a computer and have
I'm writing some code which involves running a few shell commands from Python and
I have some computers on a network, the network is somehow serial, I mean
After running some usability tests, I found that participants opened a jQuery Lightbox to
I'm running some JUnit tests on my applications. Every test has a for loop
I am running some queries to track down a problem with our backup logs
I'm running some JMeter tests against a Java process to determine how responsive a
I was running some dynamic programming code (trying to brute-force disprove the Collatz conjecture
I'm currently running some SQL which uses an IN expression to match against multiple

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.