Jump to content
Sign in to follow this  
ScriptFu

Gzip With AutoIt

Recommended Posts

ScriptFu

I am trying to pass the -c parameter to a gzip command, but cannot get autoIt to make it work.

Here is the line i am currently using,

Run('"C:\Program Files (x86)\GnuWin32\bin\gzip.exe" "C:\Users\fp\Downloads\' & $sLatestFile & '"')

This works fine, but it deletes the file after it is zipped. I need it to not delete the file, so i need to use the -c switch. Anyone have any luck getting this to work?

Thanks.

Share this post


Link to post
Share on other sites
Bowmore

This little script should get you started. It runs gzip with the output redirected to StandardOut and captures the content of StandarOut into a variable and the writes the content of the variable to a new file.

#include <Constants.au3>
Global $sCompressedData = ""
Global $iPID = -1
Global $sLatestFile = "Name of file to compress"

;Run gzip with output to Standard Out
$iPID = Run('"C:Program Files (x86)GnuWin32bingzip.exe" -c "C:UsersfpDownloads' & $sLatestFile & '"',@WorkingDir,@SW_HIDE,$STDOUT_CHILD)

; Read the compressed data from StandardOut
$sCompressedData = StdoutRead($iPID)
While Not @error
    $sCompressedData &= StdoutRead($iPID)
WEnd
; Now write the compressed data to a new file
FileWrite("C:UsersfpDownloads" & $sLatestFile & ".gz",$sCompressedData)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
ScriptFu

This little script should get you started. It runs gzip with the output redirected to StandardOut and captures the content of StandarOut into a variable and the writes the content of the variable to a new file.

#include <Constants.au3>
Global $sCompressedData = ""
Global $iPID = -1
Global $sLatestFile = "Name of file to compress"

;Run gzip with output to Standard Out
$iPID = Run('"C:Program Files (x86)GnuWin32bingzip.exe" -c "C:UsersfpDownloads' & $sLatestFile & '"',@WorkingDir,@SW_HIDE,$STDOUT_CHILD)

; Read the compressed data from StandardOut
$sCompressedData = StdoutRead($iPID)
While Not @error
$sCompressedData &= StdoutRead($iPID)
WEnd
; Now write the compressed data to a new file
FileWrite("C:UsersfpDownloads" & $sLatestFile & ".gz",$sCompressedData)

Did this work for you?

I tried and it did run, but it did not compress the file.

Share this post


Link to post
Share on other sites
SmOke_N

Have you looked at:


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
ScriptFu

Have you looked at:

I have, but that still does not use the -c switch.

Share this post


Link to post
Share on other sites
SmOke_N

No idea what -c switch is, not going to hunt it down either.

So.. Bowmore's looks correct unless the working directory is incorrect.

If the second file command line is actually what you're trying to write to, and if the gzip.exe already does that, no need for stdout, so you could do:

Run('"C:Program Files (x86)GnuWin32bingzip.exe" -c "C:UsersfpDownloads' & $sLatestFile & '"', @WorkingDir)

If that doesn't work, you could try:

Run('"C:Program Files (x86)GnuWin32bingzip.exe" -c "C:UsersfpDownloads' & $sLatestFile & '"', '"C:Program Files (x86)GnuWin32bin"')
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
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
Sign in to follow this  

×