Launching Ghostscript with parameters How to ?

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 14, 2014 12:09 pm

Launching Ghostscript with parameters How to ?

Post by loulou2522 »

Here is what walk with a cmd files
"C:\Program Files (x86)\gs\gs9.20\bin\gswin32c.exe " -dBATCH -dPDFSETTINGS=/screen -dPDFA=3 -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -dUseCIEColor -sDEVICE=pdfwrite -o "C:\Users\Patrick\Desktop\avis1.pdf" -dPDFACompatibilityPolicy=1 "C:\Users\Patrick\Documents\SEPA\SEPA_EN_COURS\SEPAMAIL\pdfa\PDFA_def.ps" "C:\Users\Patrick\Desktop\factureun.pdf" >toto.txt
I don't arrive to launch the program with purebasic and i don't know ho to do ?
Can someone help me
User avatar
Michael Vogel
Addict
Addict
Posts: 2799
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Launching Ghostscript with parameters How to ?

Post by Michael Vogel »

Maybe you can try something like this...

Code: Select all

GhostHandle=RunProgram("gswinc.exe","....","",#PB_Program_Read|#PB_Program_Open|#PB_Program_Hide)
If GhostHandle
	While ProgramRunning(GhostHandle)
		If AvailableProgramOutput(GhostHandle)
			s=ReadProgramString(GhostHandle)
		EndIf
	Wend
	GhostExitcode=ProgramExitCode(GhostHandle)
	KillProgram(GhostHandle)
	CloseProgram(GhostHandle)
	Delay(50)
EndIf
infratec
Always Here
Always Here
Posts: 7593
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Launching Ghostscript with parameters How to ?

Post by infratec »

Code: Select all

Program$ = "C:\Program Files (x86)\gs\gs9.20\bin\gswin32c.exe"
Parameter$ = "-dBATCH -dPDFSETTINGS=/screen -dPDFA=3 -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -dUseCIEColor -sDEVICE=pdfwrite -o " + #DQUOTE$ + "C:\Users\Patrick\Desktop\avis1.pdf" + #DQUOTE$ + " -dPDFACompatibilityPolicy=1 " + #DQUOTE$ + "C:\Users\Patrick\Documents\SEPA\SEPA_EN_COURS\SEPAMAIL\pdfa\PDFA_def.ps" + #DQUOTE$ + " " + #DQUOTE$ + "C:\Users\Patrick\Desktop\factureun.pdf" + #DQUOTE$

RunProgram(Program$, Parameter$)
If you want to redirect the output to the text file, then you have to open the program with

Code: Select all

#PB_Program_Read|#PB_Program_Open
Like Michael showed you.

Bernd
elwood
User
User
Posts: 30
Joined: Tue Dec 27, 2016 4:40 pm
Location: Lyon, France

Re: Launching Ghostscript with parameters How to ?

Post by elwood »

infratec wrote: #DQUOTE$
I don't know what these are. You should give loulou2522 "Chr(34)" instead.

@Michael Vogel

it should be:
s$ = ReadProgramString....

@loulou2522

This worked for me i.e. it generated the "log.txt" file containing an error:

Code: Select all

prog = RunProgram("C:\Program Files (x86)\GPLGS\gswin32c.exe","-dBATCH -dPDFSETTINGS=/screen -dPDFA=3 -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -dUseCIEColor -sDEVICE=pdfwrite -o " + Chr(34) + "C:\Users\phil\AppData\Local\Temp\gswin.pdf" + Chr(34) + " -dPDFACompatibilityPolicy=1 " + Chr(34) + "C:\Program Files (x86)\GPLGS\align.ps" + Chr(34) + " " + Chr(34) + "C:\Users\phil\AppData\Local\Temp\gswin2.pdf" + Chr(34) + " >C:\Users\phil\AppData\Local\Temp\log.txt","c:\",#PB_Program_Read|#PB_Program_Open)
If prog = 0
  Debug "Error"
Else
  CloseProgram(prog)
EndIf
What's strange is that it worked only once. Strange...

So I changed my program to follow Michael proposal and it works like a charm:

Code: Select all

prog = RunProgram("C:\Program Files (x86)\GPLGS\gswin32c.exe","-dBATCH -dPDFSETTINGS=/screen -dPDFA=3 -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -dUseCIEColor -sDEVICE=pdfwrite -o " + Chr(34) + "C:\Users\phil\AppData\Local\Temp\gswin.pdf" + Chr(34) + " -dPDFACompatibilityPolicy=1 " + Chr(34) + "C:\Program Files (x86)\GPLGS\align.ps" + Chr(34) + " " + Chr(34) + "C:\Users\phil\AppData\Local\Temp\gswin2.pdf" + Chr(34) + " >C:\Users\phil\AppData\Local\Temp\gswin.txt","c:\",#PB_Program_Read|#PB_Program_Open)
If prog
  While ProgramRunning(prog)
    If AvailableProgramOutput(prog)
         s$ = ReadProgramString(prog)
    EndIf
  Wend
  Debug s$
  KillProgram(prog)
  CloseProgram(prog)
EndIf
AmigaOS betatester
French Amiga Translation Team
Team for the Planet member
infratec
Always Here
Always Here
Posts: 7593
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Launching Ghostscript with parameters How to ?

Post by infratec »

elwood wrote:
infratec wrote: #DQUOTE$
I don't know what these are. You should give loulou2522 "Chr(34)" instead.
#DQUOTE$ is a constant which represents the value of Chr(34)
But if you read #D(ouble)QUOTE$ you know what it is. Chr(34) is only a number converted to a Character.

So for better reading of the code I prefer
#DQUOTE$ for Chr(34)
and
#CRLF$ for Chr(10) + Chr(13)

Bernd
elwood
User
User
Posts: 30
Joined: Tue Dec 27, 2016 4:40 pm
Location: Lyon, France

Re: Launching Ghostscript with parameters How to ?

Post by elwood »

Oh, these constants are not listed in the constant section of the PB manual.
Thanks for the hint.
AmigaOS betatester
French Amiga Translation Team
Team for the Planet member
User avatar
blueb
Addict
Addict
Posts: 1112
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Launching Ghostscript with parameters How to ?

Post by blueb »

elwood wrote:Oh, these constants are not listed in the constant section of the PB manual.
In the IDE...take a look at the 'Structure Viewer' on the Tools menu (or simply press Alt-S), then select the 'Constants' tab.
Type in what you need in the box provided, etc.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply