Solved

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

Posted on 2010-08-16
9
487 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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