I am trying to execute GhostScript in a batch file.
gswin32.exe ^
-dNOPAUSE ^
-sDEVICE=pdfwrite ^
-sOUTPUTFILE=output1.txt ^
-dBatch ^
"file1.txt" "file2.txt"
gswin32.exe ^
-dNOPAUSE ^
-sDEVICE=pdfwrite ^
-sOUTPUTFILE=output2.txt ^
-dBatch ^
"file1.txt" "file2.txt"
Problem is when first line is executed, it opens GhostScript window. i have to manually type quit or close the window to return the control to parent to execute the next command in batch. How can we modify batch file so it executes ghost script? Originally I am calling this file from C# program using Process.Start(ProcessInfo). Suggestions are welcome
To avoid Ghostscript opening a window, don't use gswin32.exe
.
Use gswin32c.exe
instead. (The c in the name is to indicate it's for console only...)
Also, be aware that Text files cannot serve as input to Ghostscript.
Ghostscript can only process PostScript, Encapsulated PostScript or PDF files.
You can name your output file as you please.
But your -sDEVICE=pdfwrite
will produce PDF output, so you are well advised to use a .pdf
suffix for the output file if you want to avoid confusion later.
The spelling for -dBATCH
is case sensitive.-dBatch
will not work.
(-dBATCH
causes Ghostscript to return after the last page of the job being completed -- otherwise it would switch to interactive mode and show its GS>
prompt... It's not for processing 'batches of input files', as you appear to assume.)
Your 2 commands in the batch file are using both the same input parameters.
That means the 2 output files will be the same, just have different filenames.
I recommend the following commandline scheme to use:
gswin32.exe ^
-dNOPAUSE ^
-dBATCH ^
-sDEVICE=pdfwrite ^
-sOUTPUTFILE=output2.pdf ^
"file1.ps" "file2.pdf" "file3.eps"
Use gswin32c
instead. This is a console application and won't create a window you need to manually close.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With