Results 1 to 13 of 13

Thread: Shell and Stuff

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12

    Question Shell and Stuff

    I am writting a program that runs different shell commands. One of the shell commands starts downloading files from a remote location. When you run the shell command the shell pops up and shows the amount of data received. Is there a way to grab that info from the shell and hide the shell and display it on the VB GUI?

    Any thoughts on this would be great!

    Thanks!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Yes its possible. Here is a program I did. It runs the ipconfig command from the command prompt, captures the output and puts it in a textbox.

    Its in C#, but it should'nt be a problem to convert.
    Attached Files Attached Files
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    I really appreciate that, but I can't open up the file because I don't have c# installed...

    Also would that have allowed for continuous updating?


    Thanks!

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Use notepad to open the ".cs" files. Also, what do you mean by continous updating?
    Dont gain the world and lose your soul

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    well the data streams, so it will take from 1 minute to many hours to stream the data - i want to constantly show how the progress is

    Also while we are on the topic of shell, I am also having this other problem.

    I am running this command:
    Shell("c:\replaypc\replaypc " & ipaddress & " -d > text.dat ", AppWinStyle.MaximizedFocus, True)

    it is supposed to write the output to the text.dat file. For some reason it is not writting it. Though if I go to the command line and type this in it does!
    Do you know why?

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    I looked through your code... I see the proc...

    when I do:

    proc = new Process()

    I don't know what type of variable to declare proc

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Here is the vb code:

    VB Code:
    1. Dim proc As Process
    2.  
    3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         proc = New Process()
    5.  
    6.         Dim str As String = Nothing
    7.         Dim sIn As StreamWriter
    8.         Dim sOut As StreamReader
    9.  
    10.         proc.StartInfo.FileName = "ipconfig"
    11.         proc.StartInfo.Arguments = " /all"
    12.         proc.StartInfo.UseShellExecute = False
    13.         proc.StartInfo.RedirectStandardInput = True
    14.         proc.StartInfo.RedirectStandardOutput = True
    15.         proc.StartInfo.RedirectStandardError = True
    16.         proc.Start()
    17.  
    18.         sIn = proc.StandardInput
    19.         sIn.AutoFlush = True
    20.         sOut = proc.StandardOutput
    21.  
    22.  
    23.         sIn.Write(Environment.NewLine)
    24.         sIn.Write("exit" + Environment.NewLine)
    25.         str = sOut.ReadToEnd()
    26.  
    27.         If (Not proc.HasExited) Then
    28.             proc.Kill()
    29.         End If
    30.  
    31.         TextBox2.Clear()
    32.         TextBox2.Text = str
    33.  
    34.         sIn.Close()
    35.         sOut.Close()
    36. End Sub

    Dont use the Shell command. Use the process class.
    Dont gain the world and lose your soul

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    that code looks great, but what about the StreamWriter and StreamReader? It says the two are not defined...

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    bump

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    They should be. I tried it and it worked.

    Copy and paste the code in a button click method.
    Dont gain the world and lose your soul

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    for some reason I had to type in system.io.streamreader

    the just streamreader would not work...

  12. #12
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Oh, forgot to tell you. You have to put Import System.IO at the top of the program.
    Dont gain the world and lose your soul

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    12
    Is there a way to send a command to have the window minimized? Also this isn't working exactly as I would like because the vb code waits to do something until after the code is executed... Which means it isn't streaming on the vb app what is happening - like the amount of data being downloaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width