?
Solved

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

Posted on 2010-08-16
9
Medium Priority
?
514 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

809 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