Solved

vb.net read results from a command line and paste int an array

Posted on 2010-08-16
9
481 Views
Last Modified: 2013-11-27
I have a process that runs by vb.net through the dos command line..and each time it goes through the loop it needs to print an array.. any ideas/?
0
Comment
Question by:GlobaLevel
  • 4
  • 3
  • 2
9 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33452157
What kind of application are you using ? Is it a console-application ?

What exactly do you want to do ? Run the program and from within the program printing/displaying information on the console-screen ?
0
 
LVL 3

Expert Comment

by:bkokx
ID: 33454500
The command line arguments are alread passed as an array.

Module Module1
    Sub Main(ByVal args() As String)
        Dim i As Integer
        While i < args.Length
            Console.WriteLine(i.ToString() & ": " & args(i))
            i = i + 1
        End While
    End Sub
End Module

Open in new window

0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33454746
its not in the breadcrumb above..I am using vb.net...the vb.net will call a command line..thur process.start? and launch a program to run via dos..then it will run varaibles against it and that will produce a result which will then need to be inputed into a an array variable.....then..this is extra ..will be sent to a remote db for storage...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Expert Comment

by:bkokx
ID: 33455552
Hi GlobaLevel,
Sorry but than I do not understand what your question.
The variable 'args' in the code above is an array.
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33461156
sorry..I must not be clear...

I am using vb.net to run a shell command against the DOS....the short is I need to glean the results from that and insert into variables...would this stil do?/
Module Module1
    Sub Main(ByVal args() As String)
        Dim i As Integer
        While i < args.Length
            Console.WriteLine(i.ToString() & ": " & args(i))
            i = i + 1
        End While
    End Sub
End Module
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33461989
If I understand it correctly. You start a .net-application from the DOS-prompt with parameters.
You want to read those parameters into variables for further use in your application.

Imports System.Windows.Forms 
Module Module1


        Public Sub main()

            Dim frm As New Form1
            Dim str() As String
            Dim args() As String = Split(Command$," ")
            If (UBound(str) >= 0) Then
                a = str(0).ToString
                b = str(1).ToString
            End If
            Application.Run(frm)
        End Sub  

End Module

Open in new window

0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33479199
Dhaest~

I use vb.net to open a shell or MyProcess.start command....
Open an app with the shell that is using a vb.net
then read those values that are coming form the shell into varaibles...to be used in other parts of my vb.net program...
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33479214
vb.net~~
    open DOs with Shell or MyProcess
          open app
                 dos returns values
           save values into a varaibles
    close shell
vb.net ~ takes those varibles into other parts of the vb.net program...
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33482692
You can do this if you are using a process-command in vb.net
http://www.daniweb.com/forums/thread107422.html

' Executes and waits for DOS command to complete
Private Function ExecuteDOSCmd(ByVal exe As String, _
Optional ByVal args As String = "") As String

' The string to return to the caller returned from the executed program
Dim retStr As String = ""
' The process that will that will start when the start command is executed
Dim p As New Process()
' The program to be started
p.StartInfo.FileName = exe
' Any arguments that the program needs
If args <> "" Then p.StartInfo.Arguments = args
' Do not use the system shell to start the program this is so we can 
' hide the command dos window
p.StartInfo.UseShellExecute = False
' So we can get the data output from the program we are calling
p.StartInfo.RedirectStandardOutput = True
' Show no dos window
p.StartInfo.CreateNoWindow = False
' Start the program
p.Start()
' Read the output from the program we started
retStr = p.StandardOutput.ReadToEnd()
' Wait until the program to exit.
p.WaitForExit()
Return retStr

End Function

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question