Jump to content

StderrRead reads nothing until application close


ghetek
 Share

Recommended Posts

Hey guys, I am trying to automate the process of connecting to the Tor network. Currently they do use a nice GUI called Vidalia but I want to customize and simplify the process. Currently I am working with 2 executables, tor.exe and polipo.exe. Tor was super easy to tap into, just a stdoutread. Unfortunately Polipo would not give anything on the out stream and I had to use StdErr.

The problem

For some reason, while tor easily goes from stream to console, I only get output from Polipo after it has closed. The StdErr stream returns nothing while the application is open and then spits out everything as soon as it closes. has anybody else run into this problem when reading from a console? I have attached my current script but it is still in its infancy stages.

#include <File.au3>
#include <Constants.au3>
OnAutoItExitRegister("ToolCleanup")
Global $ConnectionState = 0
Global $Hnd_Tor, $Hnd_Polipo, _
  $TorConsole, $PolipoConsole, _
  $Dir_Tor = @ScriptDir & "\Tor", _
  $DirPolipo = @ScriptDir & "\Polipo", _
  $Exe_Tor = $Dir_Tor & "\tor.exe", _
  $Conf_Tor = $Dir_Tor & "\torrc", _
  $Exe_Polipo = $DirPolipo & "\polipo.exe", _
  $Conf_Polipo = $DirPolipo & "\polipo.conf"
TorConfig($Conf_Tor)
While 1
Switch $ConnectionState
  Case 0
   $Hnd_Tor = RunTor($Exe_Tor, $Conf_Tor)
   If $Hnd_Tor <> 0 Then
    $ConnectionState = 1
    ConsoleWrite("Connection State 1 (Tor PID:" & $Hnd_Tor & ")" & @CRLF)
   EndIf
  Case 1
   If StringInStr($TorConsole, "Bootstrapped 100%", 2) Then
    $Hnd_Polipo = RunPolipo($Exe_Polipo, $Conf_Polipo)
    If $Hnd_Polipo <> 0 Then
     $ConnectionState = 2
     ConsoleWrite("Connection State 2 (Polipo PID:" & $Hnd_Polipo & ")" & @CRLF)
    EndIf
   EndIf
EndSwitch
$PolipoConsole = StdErrRead($Hnd_Polipo)
$TorConsole = StdoutRead($Hnd_Tor)
ConsoleWrite($TorConsole)
ConsoleWrite($PolipoConsole)
WEnd
Func RunTor($Exe, $Conf)
Do
  ProcessClose("tor.exe")
Until ProcessExists("Tor.exe") = 0
$hTor = Run('"' & $Exe_Tor & '" -f "' & $Conf_Tor & '"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
Return $hTor
EndFunc   ;==>RunTor
Func TorConfig($Conf)
Local $aTorConf
_FileReadToArray($Conf, $aTorConf)
For $i = 1 To $aTorConf[0]
  If StringInStr($aTorConf[$i], "DataDirectory", 2) = 1 Then
   $aTorConf[$i] = "DataDirectory " & @ScriptDir & "\Tor\data"
  EndIf
Next
_FileWriteFromArray($Conf, $aTorConf, 1)
EndFunc   ;==>TorConfig
Func RunPolipo($Exe_Polipo, $Conf_Polipo)
Do
  ProcessClose("polipo.exe")
Until ProcessExists("polipo.exe") = 0
$hPolipo = Run('"' & $Exe_Polipo & '" -c "' & $Conf_Polipo & '" ', "", @SW_SHOW, $STDIN_CHILD + $STDERR_CHILD)
Return $hPolipo
EndFunc   ;==>RunPolipo
Func ToolCleanup()
Do
  ProcessClose("polipo.exe")
Until ProcessExists("polipo.exe") = 0
Do
  ProcessClose("tor.exe")
Until ProcessExists("Tor.exe") = 0
EndFunc   ;==>ToolCleanup

Here is a link to someone else with this issue (unresolved)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...