Jump to content

Reading a programs output stream


tlman12
 Share

Recommended Posts

Alright so i have this console based application that runs and displays info within the command prompt. I need to be able to read and send that info via tcp to another server logging application.

the program is DSM from computer associats and the console app i'm running is dmsweep.exe

i have been succesfull with other applications using the stdreadout but this program dosn't seem to be, i guess, outputting the data in a standard way?

i even tried the cmd /c dmsweep.exe >> output.log and unlike most programs that output each line as it's displayed this one dosn't seem to do it

is there a way to get around this? or something else i can try?

i have also tried stdreadout($foo,true,true) and stdreadout($foo,false,true)

thank you for your help.

Link to comment
Share on other sites

  • Developers

Show the script you have tried to make it work with so we can see what you are doing.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

obvously you won't be able to run it withough dsm but here it is. maybe i am making a stupid syntax error?

i did try to change the run to a ping and it's returning my results correctly so i don't think thats it

]#include <Constants.au3>

dim $prevMsg = ""
dim $server, $nPORT
$server = IniRead("Server.ini","main","ServerIP","")
if $server = "" then Exit
local $nPORT = 33891, $nPORTclient = 33892

If $cmdLine[0] = "" Then
    MsgBox(16, "Error", "This program can not be run alone.")
Else
    TCPStartup()
    $foo = Run('cmd /c c:\temp\dmsweep.exe deploy /mgr CCSADUM /ip ' & $cmdLine[1] & " /pn 9 /pparams " & $cmdLine[2] & ",, /tu " & $cmdLine[3] & " /tp " & $cmdLine[4]','',@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
    while 1
        $msg = StdoutRead($foo,True)
        MsgBox(0,"",$msg)
        if not $msg = "" Then
            if not $msg = $prevMsg Then
                $ConnectedSocket = -1
                $ConnectedSocket = TCPConnect($server, $nPORT)
                $ConnectedSocket2 = -1
                $ConnectedSocket2 = TCPConnect($cmdLine[1], $nPORTclient)
                If @error Then
                    MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error & @crlf & @CRLF & "Please make sure the server is running and then click ok")
                    $ConnectedSocket = TCPConnect($server, $nPORT)
                    if @error then
                        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error & @crlf & @CRLF & "Still unable to connect to server, Please try again later")
                    EndIf
                EndIf
                if $ConnectedSocket > 0 Then
                    TCPSend($ConnectedSocket, $cmdLine[1] & "," & $msg)
                    TCPSend($ConnectedSocket2,$msg)
                    if StringInStr($msg,"SUCCESS") Then
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
        sleep (10)
    WEnd
    FileDelete("\\" & IniRead("Server.ini", "main", "SessionServer", "27.27.41.1") & "\Sessions\" & $cmdLine[1])
EndIf

#include <Constants.au3>

dim $prevMsg = ""
dim $server, $nPORT
$server = IniRead("Server.ini","main","ServerIP","")
if $server = "" then Exit
local $nPORT = 33891, $nPORTclient = 33892

If $cmdLine[0] = "" Then
    MsgBox(16, "Error", "This program can not be run alone.")
Else
    TCPStartup()
;~  $foo = Run('cmd /k c:\temp\dmsweep.exe deploy /mgr CCSADUM /ip ' & $cmdLine[1] & " /pn 9 /pparams " & $cmdLine[2] & ",, /tu " & $cmdLine[3] & " /tp " & $cmdLine[4]','',@SW_SHOW);,$STDERR_CHILD + $STDOUT_CHILD)
    $foo = run('cmd /c ping -t ccsdeploy','',@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
    while 1
        $msg = StdoutRead($foo,True)
        MsgBox(0,"",$msg)
        if not $msg = "" Then
            if not $msg = $prevMsg Then
                $ConnectedSocket = -1
                $ConnectedSocket = TCPConnect($server, $nPORT)
                $ConnectedSocket2 = -1
                $ConnectedSocket2 = TCPConnect($cmdLine[1], $nPORTclient)
                If @error Then
                    MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error & @crlf & @CRLF & "Please make sure the server is running and then click ok")
                    $ConnectedSocket = TCPConnect($server, $nPORT)
                    if @error then
                        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error & @crlf & @CRLF & "Still unable to connect to server, Please try again later")
                    EndIf
                EndIf
                if $ConnectedSocket > 0 Then
                    TCPSend($ConnectedSocket, $cmdLine[1] & "," & $msg)
                    TCPSend($ConnectedSocket2,$msg)
                    if StringInStr($msg,"SUCCESS") Then
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
        sleep (10)
    WEnd
    FileDelete("\\" & IniRead("Server.ini", "main", "SessionServer", "27.27.41.1") & "\Sessions\" & $cmdLine[1])
EndIf
Link to comment
Share on other sites

  • Developers

You have a syntax error in the Run() posted script but I guess you haven;t tested with this one. It has an extra quote after $cmdLine[4].

Have you tried StderrRead() to see if the output is written to stderr in stead of stdout?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You have a syntax error in the Run() posted script but I guess you haven;t tested with this one. It has an extra quote after $cmdLine[4].

Have you tried StderrRead() to see if the output is written to stderr in stead of stdout?

oh lol yeah i hand't re run it since i removed the ' >> dmsweep.log' lol but the scipt wouldn't have run at all like that

tried the stderrout

$msg = StdoutRead($foo,True) & @crlf & StderrRead($foo,true)

MsgBox(0,"",$msg)

after 3 mins i got nothing from the stdout (which i should have because i know witin 3 mins atleast the first step of the dmsweep process is complete and displayed

and on the stderr i only got the fact that i was initiating cmd prompt with a UNC path and that that was unsupported..

after it is finished with the >> i do get the output which looks like this in the dmsweep.log

but after finishing i get nothing for the stdout in autoit

C:\temp>C:\temp>

C:\temp>Contacting the deployment manager on CCSADUM.

New job id is 31492258.

Retrieving the package list.

Scanning for package CA DSM Agent + AM, RC, SD plugin(s) 12.0.1.1378 Windows_x86 NLS(ENU,DEU,FRA,JPN).

IP SCAN: Package deployed. Credentials required. (1 of 1)

Scan complete.

Deploying package CA DSM Agent + AM, RC, SD plugin(s) 12.0.1.1378 Windows_x86 NLS(ENU,DEU,FRA,JPN).

IP PROGRESS: Package posted.

IP PROGRESS: Deploying primer.

IP PROGRESS: Primer installed.

IP PROGRESS: Package deployed.

Deployment complete.

DEPLOYMENT SUMMARY

===============================================================================

IP SUCCESS: Package deployed.

===============================================================================

C:\temp>

Edited by tlman12
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...