How to use gzip inside a .bat on Win 7

Leon1998

New member
Local time
2:52 PM
Messages
10
Hi,

I'm able to compress files using gzip in CMD but when I use gzip inside a .bat file I just get a loop. I tried various commands, tried to simplify the options, and also tried to specify the path to the input file within the .bat but it didn't work.
I'm out of ideas.

Any help is appreciated.


gzip 1.3.12, Win7 Ultimate x64.
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Windows 7 Ultimate x64 SP1
CPU
Intel i7 7700k
Motherboard
Asus H170 Pro
Memory
Kingston Fury 4GB DDR4
Graphics Card(s)
NVIDIA GeForce GT 440 (2 GB)
Monitor(s) Displays
Samsung
Screen Resolution
1360x768
Hard Drives
Seagate Barracuda 7200
Seagate Backup+ SL USB Device
Antivirus
Eset Smart Security 8
Browser
Waterfox
Hi Leon1998,

Besides the correct path are you using the .exe within the Batch file?

I hope this helps!
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Hi Leon1998,

Besides the correct path are you using the .exe within the Batch file?

I hope this helps!

Thank you, it worked, but I can't understand why because other applications I've used don't need .exe inside the .bat file, like:

Code:
ffmpeg -i %1 -map 0:a:0 -vn -sn -dn -acodec copy -map_chapters...
gzip.exe is in PATH directory, and I can easily call it in CMD like "gzip -9 ... " without .exe appended to it so I don't know why it'd need it inside a .bat :confused:
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Windows 7 Ultimate x64 SP1
CPU
Intel i7 7700k
Motherboard
Asus H170 Pro
Memory
Kingston Fury 4GB DDR4
Graphics Card(s)
NVIDIA GeForce GT 440 (2 GB)
Monitor(s) Displays
Samsung
Screen Resolution
1360x768
Hard Drives
Seagate Barracuda 7200
Seagate Backup+ SL USB Device
Antivirus
Eset Smart Security 8
Browser
Waterfox
What does exactly means "I just get a loop"? Be as specific as you can.

Bat files follow exactly the same rules as issuing commands directly in the prompt, the .exe extension is never needed (to be 100% accurate, it depends on the "comspec" variable, which is rarely changed) and the full path is needed if it's not in the path variable or in the current directory. Also be careful with quoting if the command contains paths with possible spaces.
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
What does exactly means "I just get a loop"?
(computing) a set of instructions that is repeated again and again
When I run the .bat without .exe, CMD just shows a loop of the parameters, like so:

Code:
gzip --best --keep --verbose --best
gzip --best --keep --verbose --best
gzip --best --keep --verbose --best
gzip --best --keep --verbose --best
gzip --best --keep --verbose --best
...
The actual parameters specified in the .bat :

Code:
gzip --best --keep --verbose %1
pause
I don't know why it adds a second "--best" to it in the CMD.
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Windows 7 Ultimate x64 SP1
CPU
Intel i7 7700k
Motherboard
Asus H170 Pro
Memory
Kingston Fury 4GB DDR4
Graphics Card(s)
NVIDIA GeForce GT 440 (2 GB)
Monitor(s) Displays
Samsung
Screen Resolution
1360x768
Hard Drives
Seagate Barracuda 7200
Seagate Backup+ SL USB Device
Antivirus
Eset Smart Security 8
Browser
Waterfox
I have some vague idea of what's going on, but one last thing to confirm. How are you calling the bat file? What's the full command line you issue to run your file?

The possible cause I can think of is the lack of proper quotiong in the last parameter, since it's supplied from the command line (%1) a file with spaces can give problems and some very particular case can end up in a circular invocation of the same bat file over and over.
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
How are you calling the bat file? What's the full command line you issue to run your file?
As you can see I've specified "%1" in the .bat, so I just drag&drop the file onto the .bat file to compress it.

The possible cause I can think of is the lack of proper quotiong in the last parameter, since it's supplied from the command line (%1) a file with spaces can give problems and some very particular case can end up in a circular invocation of the same bat file over and over.
I highly doubt that the problem is the lack of proper quoting because I use "%1" without the quotation marks in my other .bat files as well, one working example is already provided in post #3.
Anyway, just to be sure I supplied the full path to the file I want to compress with and without quotation marks, neither way worked. I also made sure there were no spaces in neither the path nor the file name itself.

When the full path is specified that last "--best" is replaced with the path :

Code:
gzip --best --keep --verbose "F:\1.txt"
gzip --best --keep --verbose "F:\1.txt"
gzip --best --keep --verbose "F:\1.txt"
gzip --best --keep --verbose "F:\1.txt"
gzip --best --keep --verbose "F:\1.txt"
...
Code:
gzip --best --keep --verbose F:\1.txt
gzip --best --keep --verbose F:\1.txt
gzip --best --keep --verbose F:\1.txt
gzip --best --keep --verbose F:\1.txt
...
Couldn't the cause be gzip.exe itself ?

P.S. I should mention that gzip.exe is in a custom PATH directory, but I don't think that should matter because there are other applications in that particular directory also which are used inside .bat files without any problem.
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Windows 7 Ultimate x64 SP1
CPU
Intel i7 7700k
Motherboard
Asus H170 Pro
Memory
Kingston Fury 4GB DDR4
Graphics Card(s)
NVIDIA GeForce GT 440 (2 GB)
Monitor(s) Displays
Samsung
Screen Resolution
1360x768
Hard Drives
Seagate Barracuda 7200
Seagate Backup+ SL USB Device
Antivirus
Eset Smart Security 8
Browser
Waterfox
Back
Top