Jump to content

Sending and Reading data to an exe using Stream controls


Rishav
 Share

Recommended Posts

Hi all

I have an .net exe which compares two excel files and tells me if they are same or different.

I need to use this exe in my scripts so i can batch compare hundreds of excel files.

to invoke the exe i need to open the command window and type in

:> "Excel Compare.exe" "1st excel file path" "1st excel file path"

the stderr is set to 0 if files are same and 1 if they are different. Furthermore, if the files are different the command window shows me the row and column numbers which are different.

I am pretty new to this area of autoit. how do i send and receive the values to the exe. I want the entire process to be silent so that no cmd window shows up. any ideas?

i dont even know how to start up the exe and keep it running.

$pid = Run("E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe", "E:\Automata\main\Automata Scripts\External Tools\Excel Comparer", @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)

doesn't really helps.

Link to comment
Share on other sites

Hi all

I have an .net exe which compares two excel files and tells me if they are same or different.

I need to use this exe in my scripts so i can batch compare hundreds of excel files.

to invoke the exe i need to open the command window and type in

:> "Excel Compare.exe" "1st excel file path" "1st excel file path"

the stderr is set to 0 if files are same and 1 if they are different. Furthermore, if the files are different the command window shows me the row and column numbers which are different.

I am pretty new to this area of autoit. how do i send and receive the values to the exe. I want the entire process to be silent so that no cmd window shows up. any ideas?

i dont even know how to start up the exe and keep it running.

$pid = Run("E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe", "E:\Automata\main\Automata Scripts\External Tools\Excel Comparer", @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)

doesn't really helps.

Hi Rishav,

i would start like this. Because i don't know exactly how your returns are set (only with StdErr), this may give you hint to work with:

#include <file.au3>
#include <array.au3>

$path1 = "Path to excel files 1"
$path2 = "Path to excel files 2"
$arexcel1 = _FileListToArray ($path1, "*.xls", 1)
$arexcel2 = _FileListToArray ($path2, "*.xls", 1)
Dim $arresult [1] [3]
$count = 0
For $i = 1 To UBound ($arexcel1) - 1
    For $j = 1 To UBound ($arexcel2) - 1
        $pid = Run('"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe "' & $path1 & "\" & $arexcel1 [$i] & _
        " " & $path2 & "\" & $arexcel2 [$j], '"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer"', @SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)
        ; use @SW_HIDE to run hidden
        ; 0 and 1 and Rows and Column are set with StdErr ?!?
        While 1
            $line = StderrRead($pid)
            If @error Then ExitLoop
            If StringInStr ($line, "0") Or StringInStr ($line, "1") Then
                $arresult [$count] [0] = $arexcel1 [$i]
                $arresult [$count] [1] = $arexcel2 [$j]
                $arresult [$count] [2] = $line
                $count += 1
                ReDim $arresult [$count + 1] [3]
            EndIf
            sleep (20)
        Wend
    Next
Next
_ArrayDisplay ($arresult)

;-))

Stefan

P.S: Edit because of copy / paste mistake

Edited by 99ojo
Link to comment
Share on other sites

Hi Stefan. Nice to see you again.

the exe handles the excel size and stuff so I don't need to get the row/column counts.

Maybe This will help you help me. :)

Posted Image

Posted Image

Posted Image

so i guess, i need something like this;

#include <file.au3> 
$file1 = "C:\Documents and Settings\rishavs\Desktop\Copy of TC_SCD_01_Pass1_PendingUpdates.xls" 
$file2 = "C:\Documents and Settings\rishavs\Desktop\TC_SCD_01_Pass1_PendingUpdates.xls"  

Dim $arresult[1][3] $count = 0  

$pid = Run('"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe " & $file1 & $file2 ', '"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer"', @SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD) 

; 0 and 1 and Rows and Column are set with StdErr ?!? 

While 1     
   $line = StderrRead($pid)   
WEnd

ie. $file1 and $file2 need to be in the main command only, under double quotes. so far i can't even get past the run command. I am getting tangled up in the quotes.

Link to comment
Share on other sites

Hi,

#include <file.au3>
#include <Constants.au3> ; that was missing as well
$file1 = '"C:\Documents and Settings\rishavs\Desktop\Copy of TC_SCD_01_Pass1_PendingUpdates.xls"'
$file2 = '"C:\Documents and Settings\rishavs\Desktop\TC_SCD_01_Pass1_PendingUpdates.xls"'  

;Dim $arresult[1][3] $count = 0  

$pid = Run('"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe "' & $file1 & " " & $file2, '"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer"', @SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD) 

; 0 and 1 and Rows and Column are set with StdErr ?!? 
; If you want to handle output with AutoIT, you have to code some stuff in between the While Loop
While 1     
   $line = StderrRead($pid)
   If @error Then ExitLoop
   ;Coding for output
Wend

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Thanks again Stefan, but I am still stuck at the run part. the exe isn't running. :)

If i run it via command line, i get a new process in the task manager. but running via autoit does nothing.

the way i need to write in the command line is;

[b]c:/>[/b]"c:/tools/Excel Compare.exe" "c:/folder/file1.xls" "c:/folder/file2.xls"

ie. i need the double quotes around the exe path and the excel paths. but i am still tangled up in the double quotes somewhere.

this somehow does runs the exe for me. I don't know how to use the file path variables with it.

$pid = Run('"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe" "C:\Documents and Settings\rishavs\Desktop\TC_SCD_01_Pass1_PendingUpdates.xls" "C:\Documents and Settings\rishavs\Desktop\TC_SCD_01_Pass1_PendingUpdates.xls"', "", @SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)

Edit: logically your code looks proper. you have the quotes around the file paths in the declaration and are calling it in the run command. but its not working for me. ;)

EDIT: whoops! i got it to initialize. we were missing a [space] so that two commands were getting glued together.

this works;

$pid = Run('"E:\Automata\main\Automata Scripts\External Tools\Excel Comparer\Excel Comparer.exe"' & " " & $file1 & " " & $file2, "", @SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)

Now to stage 2. getting the stdout from it. gimme 5 mins to try it out.

Edited by Rishav
Link to comment
Share on other sites

Heh. then its ninja deleting. :)

$pid = Run('"C:\ExcelCompare\ExcelComparer.exe"' & " " & $file1 & " " & $file2, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

sleep(15000)

$err = StderrRead($pid)
$out = StdoutRead($pid)

MsgBox(0,$pid, $err & @CRLF & $out)

Now I can get the stderr. but i am confused with the timing. My exe takes around 12-13 seconds to do the comparison.

if i dont put in a sleep command, my output is null. if i put in a sleep for more than 15 sec, i get the output.

i'd rather use the runwait command but it also gives me null output. any ideas?

Link to comment
Share on other sites

Heh. then its ninja deleting. :)

$pid = Run('"C:\ExcelCompare\ExcelComparer.exe"' & " " & $file1 & " " & $file2, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

sleep(15000)

$err = StderrRead($pid)
$out = StdoutRead($pid)

MsgBox(0,$pid, $err & @CRLF & $out)

Now I can get the stderr. but i am confused with the timing. My exe takes around 12-13 seconds to do the comparison.

if i dont put in a sleep command, my output is null. if i put in a sleep for more than 15 sec, i get the output.

i'd rather use the runwait command but it also gives me null output. any ideas?

Hi,

without the sleep you straight read the stream once.

Because your exe is still running, you have no output.

Instead of the sleep you should use a while loop for reading the streams.

e.g:

While ProcessExists ($pid)     
   $line = StdOutRead($pid)
    $err = StderrRead ($foo)
   $line &= $line ; you might add also $err &= $err
   sleep (200)
WEnd
MsgBox (0,"", $pid & @crlf & $line & @crlf & $err)

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

$pid = Run('"C:\ExcelCompare\ExcelComparer.exe"' & " " & $file1 & " " & $file2, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose("ExcelComparer.exe")
    $out = StdoutRead($pid)

    MsgBox(0, "STDOUT read:", $out)

Processwaitclose seems to work too. i'll give the loops a try later on. but the way the exe is coded, it gives an stdout stream at the very end of execution and not at intervals. so I don't think that i need to keep checking on regular intervals. anyway, i'll experiment some more. thanks a lot for you help, as usual. :)

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...