Jump to content

Running a Windows program and piping output to a textfile


Recommended Posts

Hi

I'm new to AutoIt and am trying to convert some Perl scripts to AutoIT.

I have a Perl script to backup some files using WinZIP command line program (WZZIP) and pipe the text output to a logfile.

I then examine the logfile for any errors.

I've managed to convert the script to AutoIT and I can get it to call WZZIP and create the required ZIP file.

But instead of the output being piped to a logfile (e.g. " > logfile.txt") the carat character ">" is being interpreted by WinZIP as a additional file to backup and results in a WinZip error saying there is no file called ">" to backup, the same thing occurs with the "logfile.txt" reference. Consquently all the text output from WinZip of what files are being backed up is going to the console window rather than a text file.

It looks like the AutoIT Run command is calling WinZip but "> Log. txt" is being interpreted as parameters by Winzip rather than a piped command. Yet this type of call works in Perl.

Here's part of my code

$dt1 is todays date

$tm1 is the time now

The above date/time works fine, it's just the piping output I'm having a problem with

# Zipfile name
$zip1 = "Agent_" & $dt1 & "_" & $tm1 & ".zip"

# Path to output directory
$pth1 = "C:\My Files\Install 1\"

# Directory to backup
$pth2 = "C:\Documents and Settings\Special K\My Documents\COMMSbase\Agent\Data\*.*"

# WinZip program
$prg1 = "C:\My Files\Utilities\WinZip\WZZip"

# WinZip options
$opt1 = "-a -p -rP"

# Concatenate output path and Zipfile name
$zip2 = $pth1 & $dt1 & "_" & $dy2 & $zip1

# Logfile
$log1 = $pth1 & $dt1 & "_" & $dy2 & "\Agent_" & $dt1 & "_" & $tm1 & "_Log.txt"

ConsoleWrite( $tm1 & " Backup Agent files..." & @CRLF )
ConsoleWrite( "Filename: " & $zip1 & @CRLF )

Run( $prg1 & " " & $opt1 & " """ & $zip2 & """ """ & $pth2 & """ > """ & $log1 & """" )

Should I be using a different command than "Run" to call WinZIP as I have the pipe embedded in the call ?

Link to comment
Share on other sites

Maybe helps.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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