Jump to content

How to Pipe from ShellexecWait to .txt


Recommended Posts

Ok well I have my script that reads a .csv file splits the strings to form a commandline working pretty good.. however

The Test.exe opens a Command Prompt Window with output I want to capture into a log so I can catch issues with the dlls being tested.

Here is my script so far:

; Script Start - Add your code below here

#include <GUIConstants.au3>

#include <string.au3>

#include <file.au3>

Const $LOGPATH = "C:\TheFiles\" & "Harness.txt"

Const $StartHarness = "Autoit Harness Starting..." & @CRLF

Const $EndHarness = "Autoit Harness Ending..." & @CRLF

Dim $dllPath = @ProgramFilesDir & "\THEFILES\Agents\"

Dim $fDirPath = "C:\THEFILES\"

Dim $Harness = "C:\THEFILES\TestHarness.exe"

_FileWriteLog($LOGPATH, $StartHarness, 0)

Dim $file = FileRead("test.csv")

If $file = -1 Then

MsgBox(0, "error", "File doesn't exist or can't be read")

_FileWriteLog($LOGPATH, "File doesn't exist", -1)

Exit

EndIf

Dim $avlines = StringSplit($file, @CRLF, 1)

Dim $value1, $value2, $value3, $value4, $input

For $i = 1 To $avlines[0]

$input = StringSplit($avlines[$i], ",")

$value1 = $input[1]

$value2 = $input[2]

$value3 = $input[3]

$value4 = $input[4]

;$ExpReturn = $input[5]

$Commandline = ' -dll "'& $dllPath&$value1 & '" -name ' & $value2 & ' -xml ' & $fDirPath&$value3 & ' -in ' & $fDirPath&$value4

_FileWriteLog($LOGPATH, "Executing" & $Harness&$Commandline, -1)

ShellExecuteWait($Harness, $Commandline)

;MsgBox(0, "Command Output", $Harness&$Commandline )

$ReturnVal = ShellExecuteWait($Harness, $Commandline)

;_FileWriteLog($LOGPATH, "Command return code:" & $ReturnVal, -1)

Next

_FileWriteLog($LOGPATH, $EndHarness, 0)

I have tried:

ShellExecuteWait($Harness, $Commandline & " > C:\THEFILES\OUTPUT.txt") no luck piping but the script runs and the tests run

I have tried:

RunWait(@ComSpec "/C" & $Harness & $Commandline & " > C:\THEFILES\output.txt") no luck with anything as it errors out without running any commands HELP???

Link to comment
Share on other sites

Ok well I have my script that reads a .csv file splits the strings to form a commandline working pretty good.. however

The Test.exe opens a Command Prompt Window with output I want to capture into a log so I can catch issues with the dlls being tested.

Here is my script so far:

; Script Start - Add your code below here

#include <GUIConstants.au3>

#include <string.au3>

#include <file.au3>

Const $LOGPATH = "C:\TheFiles\" & "Harness.txt"

Const $StartHarness = "Autoit Harness Starting..." & @CRLF

Const $EndHarness = "Autoit Harness Ending..." & @CRLF

Dim $dllPath = @ProgramFilesDir & "\THEFILES\Agents\"

Dim $fDirPath = "C:\THEFILES\"

Dim $Harness = "C:\THEFILES\TestHarness.exe"

_FileWriteLog($LOGPATH, $StartHarness, 0)

Dim $file = FileRead("test.csv")

If $file = -1 Then

MsgBox(0, "error", "File doesn't exist or can't be read")

_FileWriteLog($LOGPATH, "File doesn't exist", -1)

Exit

EndIf

Dim $avlines = StringSplit($file, @CRLF, 1)

Dim $value1, $value2, $value3, $value4, $input

For $i = 1 To $avlines[0]

$input = StringSplit($avlines[$i], ",")

$value1 = $input[1]

$value2 = $input[2]

$value3 = $input[3]

$value4 = $input[4]

;$ExpReturn = $input[5]

$Commandline = ' -dll "'& $dllPath&$value1 & '" -name ' & $value2 & ' -xml ' & $fDirPath&$value3 & ' -in ' & $fDirPath&$value4

_FileWriteLog($LOGPATH, "Executing" & $Harness&$Commandline, -1)

ShellExecuteWait($Harness, $Commandline)

;MsgBox(0, "Command Output", $Harness&$Commandline )

$ReturnVal = ShellExecuteWait($Harness, $Commandline)

;_FileWriteLog($LOGPATH, "Command return code:" & $ReturnVal, -1)

Next

_FileWriteLog($LOGPATH, $EndHarness, 0)

I have tried:

ShellExecuteWait($Harness, $Commandline & " > C:\THEFILES\OUTPUT.txt") no luck piping but the script runs and the tests run

I have tried:

RunWait(@ComSpec "/C" & $Harness & $Commandline & " > C:\THEFILES\output.txt") no luck with anything as it errors out without running any commands HELP???

I don't fully understand what you're trying to do because I don't know what Test.exe is or the exe's your are using in your script. Anyway, I would recommend first getting a command string that will work as you want from the command prompt, and then use RunWait instead of ShellExecuteWait. If you can't get what you want from the command prompt then you'll never get your script to do it IMO.

If you form the command string to use with RunWait($Command) you can easily check it will work by having a line

ConsoleWrite($Command & @CR) to see if it is correct.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This script is automating a series of tests against various dlls in our product.

It works no problem the only thing I want to do is Capture the Output from the Dll... it pops open a command window and is there only for the duration of that test then that data is lost.

if I type the command without the script:

Test.exe -dll Test.dll -name TestName -xml Test.xml -in Parameter.txt > output.log it works I am able to capture those details.

I would like the automation script to capture that output as well.

Does this explain it better?

Link to comment
Share on other sites

  • Developers

You posted RunWait(@comspec...) is faulty as you are missing spaces around the "/c"parameter.

Try:

RunWait(@ComSpec " /C " & $Harness & $Commandline & " > C:\THEFILES\output.txt")
Edited by 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

You posted RunWait(@comspec...) is faulty as you are missing spaces around the "/c"parameter.

Try:

RunWait(@ComSpec " /C " & $Harness & $Commandline & " > C:\THEFILES\output.txt")

Tried that and this is waht I get now... I know its sytax but not sure where:

C:\THEFILES\TestHarness_Using_csv-working.au3 (53) : ==> Error in expression.:

RunWait(@ComSpec " /C "& $Harness & $Commandline & " > C:\THEFILES\output.txt")

RunWait(^ ERROR

>Exit code: 1 Time: 0.350

I am a newb to this language and all but I really think If I can get this running it will be easy for my testers to use and manage.

Link to comment
Share on other sites

  • Developers

Tried that and this is waht I get now... I know its sytax but not sure where:

C:\THEFILES\TestHarness_Using_csv-working.au3 (53) : ==> Error in expression.:

RunWait(@ComSpec " /C "& $Harness & $Commandline & " > C:\THEFILES\output.txt")

RunWait(^ ERROR

>Exit code: 1 Time: 0.350

I am a newb to this language and all but I really think If I can get this running it will be easy for my testers to use and manage.

that should be:

RunWait(@ComSpec & " /C " & $Harness & $Commandline & " > C:\THEFILES\output.txt")

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

Tried that and this is waht I get now... I know its sytax but not sure where:

C:\THEFILES\TestHarness_Using_csv-working.au3 (53) : ==> Error in expression.:

RunWait(@ComSpec " /C "& $Harness & $Commandline & " > C:\THEFILES\output.txt")

RunWait(^ ERROR

>Exit code: 1 Time: 0.350

I am a newb to this language and all but I really think If I can get this running it will be easy for my testers to use and manage.

Ok I figured out what I was missing it was &

here is the working RunWait command: RunWait(@ComSpec & " /C " & $Harness & $Commandline & " > C:\THEFILES\output.txt")

however it overwrites the previous input so now I will have to learn how to Append the log :D

what a great learning experience this has been so far

Link to comment
Share on other sites

  • Developers

Ok I figured out what I was missing it was &

here is the working RunWait command: RunWait(@ComSpec & " /C " & $Harness & $Commandline & " > C:\THEFILES\output.txt")

however it overwrites the previous input so now I will have to learn how to Append the log :D

what a great learning experience this has been so far

Thats basic DOS/Batch stuff:)

> = Overwrite the file

>> Append to the existing file.

One other option you have is to use the AutoIt3 method of retrieving the Console output using Run() and StdoutRead(). Just read the helpfile for a nice example.

Jos

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

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