Solved

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

Posted on 2010-08-16
9
457 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now