The situation
I'm sitting at the receiving end of program A (redmon, a port monitor). I need to write a batch script that program A can call to pipe a large amount of data (PostScript) into.
Whenevern program A calls my batch script, I need to pass that data on to program B (Ghostscript) and eventually have program C (called dosomething
here) do something with the output of program B.
How it would work with Bash (Unix shell)
In a bash script, I'd write a script (let's call it myscript.sh
) like:
#!/bin/bash
cat - | gs -sDEVICE=pdfwrite -o test.pdf -f -
dosomething test.pdf
This would work work perfectly when one pipes some data into it:
cat testdata.ps | myscript.sh
Will it work on with a Windows Batch file?
As this is for Windows, I need something that can be called like
type testdata.ps | myscript.bat
because, effectively, this is how program A would call myscript.bat
. So I tried translating the bash approach 1:1 to a batch file:
@echo off
type con | "%PROGRAMFILES%\gs\gs9.16\bin\gswin32c" -o test.pdf -f -
dosomething test.pdf
The problem is, type con
doesn't seem to recognize when there's nothing left to process and the batch script therefore hangs. So, what can I do?
I tried if it might work in reverse, like
"%PROGRAMFILES%\gs\gs9.16\bin\gswin32c" -o test.pdf -f - < CON
but no luck either. An attempt at copying CON
to a file failed as well
copy con test.ps
How would one go about this? It all boils down to capturing the entire piped content and recognizing when program A is closing the pipe.