Process input / output need help

baxter

Member
Joined
Apr 27, 2005
Messages
5
Hey everyone new here and to vb.net so first off Id like to say HI :D

So heres my problem I have written a gui for a security tool that checks password strenght (john the ripper). I am having a problem outputting the resulting output to a textbox. Now I think it may lie in my threading not sure.

heres the code

heres the code for the program to run

Public Sub run()
If multirun = 1 Then
multijob()
Else
FileOpen(1, "john.ini", OpenMode.Output)
PrintLine(1, txt1.Text & rules & Txt3.Text)
FileClose(1)
If txtsalt.Text = String.Empty And chk1.Checked = True Then
MsgBox("Salt box is checked and empty!")
ElseIf chksingl.Checked = True Then
inputText = "john -si " & txtpass.Text
ElseIf Chkdouble.Checked = True Then
inputText = "john -external:double " & txtpass.Text
ElseIf chk1.CheckState = 1 Then
inputText = "john -w:" & txtword.Text & " -rules -salts:" & txtsalt.Text & " " & txtpass.Text
ElseIf chk1.CheckState = CheckState.Unchecked And chksingl.Checked = False And Chkdouble.Checked = False Then
inputText = "john -w:" & txtword.Text & " -rules " & txtpass.Text
End If
txt2.AppendText("John The Ripper Has Started" & System.Environment.NewLine)
End If
Readlines()
End Sub

Heres where the thread is supposed to read the output.

Private Sub Readlines()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.StartInfo.RedirectStandardInput = True
myProcess.Start()
myProcess.StandardInput.WriteLine(inputText)
myProcess.StandardInput.WriteLine("exit")
cmd1.Enabled = False
Do While Not myProcess.HasExited
line = myProcess.StandardOutput.ReadLine & System.Environment.NewLine
If Not line.StartsWith("Microsoft") Xor line.StartsWith("(C)") Then
If line.Chars(0) = Chr(13) Then
line = line.Replace(Chr(13), Chr(0))
Else
txt2.AppendText(line)
End If
End If
Loop
myProcess.StandardInput.Close()
myProcess.Close()
cmd1.Enabled = True
Exit Sub
End Sub


Now I know theres something wrong it does print some text but seems to die or waits till it ends. Sorry if this is a simple thing I am missing this is my first appilication

thanks for your help

bax
 
okay I have got it almost working but the thread thats reading the output seems to die while reading or stops waiting for a response

heres the code for the thread

Public Sub Readlines()
cmd1.Enabled = False
Do While Not myprocess.HasExited()
line = myprocess.StandardOutput.ReadLine & System.Environment.NewLine
If Not line.StartsWith("Microsoft") Xor line.StartsWith("(C)") Then
If line.Chars(0) = Chr(13) Then
line = line.Replace(Chr(13), Chr(0))
Else
txt2.AppendText(line)
MsgBox(line)
End If
End If
Loop
MsgBox("has ended")
cmd1.Enabled = True
End Sub

everything else is working. How can I make it work? it works for a bit then dies if nothings sent to it in awhile
 
You need to call Application.DoEvents() inside of your Do Loop.
Also, FYI: Do Until ... Loop is much more nice sounding than Do While Not ... Loop (imo)
and FYI2: You really should avoid those FileOpen() and PrintLine() legacy VB compatibility functions and opt for the StreamWriter and StreamReader. :)
 
worked great for one of the ways the program is run. But I think I found a problem. it seems that the process I am running uses another process called ntvd.exe which passes the information to cmd.exe the problem Im having is that my thread is going into waitsleepjoin mode and not coming back when information is passed to it. if I try and interupt it stops the thread.

Not sure what I should do :(

heres the code if you need it as well

THREAD
Public Sub Readlines()
cmd1.Enabled = False
txt2.AppendText("thread state is:" & oThread.ThreadState & System.Environment.NewLine)
Do Until myprocess.HasExited
line = myprocess.StandardOutput.ReadLine & System.Environment.NewLine
If Not line.StartsWith("Microsoft") Xor line.StartsWith("(C)") Then
If line.Chars(0) = Chr(13) Then
line = line.Replace(Chr(13), Chr(0))
Else
txt2.AppendText(line)
txt2.AppendText("thread state is:" & oThread.ThreadState & System.Environment.NewLine)
End If
End If
Application.DoEvents()
Loop
myprocess.Kill()
MsgBox("ended")
cmd1.Enabled = True
End Sub
 
Back
Top