Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Command Prompt

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Resolved [RESOLVED] [2005] Command Prompt

    I'm trying to run a file called mkisofs.exe via command prompt like so:

    Code:
        Private Sub CMDAutomate()
            Dim myProcess As New Process
            Dim StartInfo As New System.Diagnostics.ProcessStartInfo
            StartInfo.FileName = "cmd"
            StartInfo.RedirectStandardInput = True
            StartInfo.RedirectStandardOutput = True
            StartInfo.UseShellExecute = False
            StartInfo.CreateNoWindow = True
            myProcess.StartInfo = StartInfo
            myProcess.Start()
            Dim SR As System.IO.StreamReader = myProcess.StandardOutput
            Dim SW As System.IO.StreamWriter = myProcess.StandardInput
            SW.WriteLine(Convert.ToChar(34) & "C:\record\mkisofs.exe" & Convert.ToChar(34) & " -J -joliet-long -jcharset " & Convert.ToChar(34) & "iso8859-1" & Convert.ToChar(34) & " -l -r -V " & Convert.ToChar(34) & txtLabel.Text & Convert.ToChar(34) & " -o " & Convert.ToChar(34) & "C:\TEST.iso" & Convert.ToChar(34) & " " & Convert.ToChar(34) & "D:\" & Convert.ToChar(34))
            SW.WriteLine("exit")
            Results = SR.ReadToEnd
            MsgBox(Results)
            SW.Close()
            SR.Close()
        End Sub

    mkisofs.exe takes a long time to complete it's task, but for some reason that code exits out seconds after starting. I've tested the command to run mkisofs and it works, so it's gotta be something with code.


    My second question is how to constantly get updates from the command prompt, eg: Run mkisofs.exe via command prompt, get every new line (MKISOFS.exe creates a new line saying:
    10%
    20%
    30% complete, blah blah blah

    So I can update my app's progress bar.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Command Prompt

    First of all, I don't think you need to launch the command prompt. I think you can start the process and redirect the standard input to your application and you will get the same effect.

    Second, I think instead of doing a readtoend, you need to continually read the stream readers output and process the percentages. Doing a ReadToEnd will probably read whatever is currently in the stream and then be done, while the process is still actually working.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Command Prompt

    My problem with starting the exe directly is I get this message:

    StandardOut has not been redirected or the process hasn't started yet.

  4. #4
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    Re: [2005] Command Prompt

    Here is some code I slapped together

    Code:
     
    Dim p As New Process
    Dim zztop As New ProcessStartInfo
    
            zztop.CreateNoWindow = True
            zztop.Arguments = "yahoo.com"
            zztop.FileName = "nslookup"
            zztop.RedirectStandardOutput = True
            zztop.UseShellExecute = False
    
            p.StartInfo = zztop
            p.Start()
    
            Dim stream1 As String = p.StandardOutput.ReadToEnd
            RichTextBox1.Text = stream1
    I think that will head you in the write direction at least, and you can probably figure out the rest.

    - Joe
    Last edited by joe1985; Oct 2nd, 2007 at 06:58 PM. Reason: for got Dim p As New Process

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Command Prompt

    Sweet, it worked. Now I just need to read the text as it's created.

  6. #6
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    Re: [2005] Command Prompt

    Sorry for giving you a fish but.....

    Code:
        Do Until p.StandardOutput.EndOfStream = True
                Console.WriteLine(p.StandardOutput.ReadLine())
            Loop
    - Joe

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Command Prompt

    I noticed an issue so far, with my method and yours, with mkisofs.exe, if you run with Output = True and ShellExec = False, it ends at around 2,000kb usage (Task manager).

    Meaning, it doesn't create or do anything if RedirectOutput = True and UseShellExec = False
    Last edited by tylerm; Oct 3rd, 2007 at 06:33 PM.

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