[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.
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.
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.
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
Re: [2005] Command Prompt
Sweet, it worked. Now I just need to read the text as it's created.
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
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