Recent

Author Topic: Running gswin64c from an Apache CGI on Windows  (Read 3177 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Running gswin64c from an Apache CGI on Windows
« Reply #15 on: October 10, 2020, 02:56:50 pm »
Hi!

stdout file looks good.

As I have no new ideas anymore let's start at the other end:

What does windows tell about the printer status?

Connected, enough paper, enough toner or ink ???
Are there some print jobs waiting in the queue??

Winni

martinrame

  • Full Member
  • ***
  • Posts: 119
Re: Running gswin64c from an Apache CGI on Windows
« Reply #16 on: October 10, 2020, 03:24:37 pm »
I did something similar back in the day with Windows NT4 - the issue back then was that the "system user" did not have access to the printer. I no longer recall how I fixed it, but there was a way. A quick Google suggests this might help.

Tried this, but didn't work. Also changed the Apache2 service's user to Administrator (the same user I used for testing the command line app), but also didn't work.

martinrame

  • Full Member
  • ***
  • Posts: 119
Re: Running gswin64c from an Apache CGI on Windows
« Reply #17 on: October 10, 2020, 03:29:56 pm »
Hi!

stdout file looks good.

As I have no new ideas anymore let's start at the other end:

What does windows tell about the printer status?

Connected, enough paper, enough toner or ink ???
Are there some print jobs waiting in the queue??

Winni

Yes, it does work perfectly. As I mentioned earlier, I created (and posted here) a command line program to call gswin64c.exe  with the same parameters as the CGI and it works as expected.

Also every time I send a file for printing with the CGI I check the printer spool and nothing shows there. Also, in the Task Manager, the CPU % of the gswin64c program stays at 0, when it should use some CPU (it uses ~20% when run from command line).
« Last Edit: October 10, 2020, 03:31:51 pm by martinrame »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Running gswin64c from an Apache CGI on Windows
« Reply #18 on: October 10, 2020, 05:08:54 pm »
maybe you might want to resolve the printer name first and actually use that instead of the %printer% because that is not going to get resolved as far as I know.

Use the printer's name as you would like a PRN file.

In the old days it used to be LPT1, don't know about now.

The only true wisdom is knowing you know nothing

martinrame

  • Full Member
  • ***
  • Posts: 119
Re: Running gswin64c from an Apache CGI on Windows
« Reply #19 on: October 10, 2020, 05:23:01 pm »
maybe you might want to resolve the printer name first and actually use that instead of the %printer% because that is not going to get resolved as far as I know.

Use the printer's name as you would like a PRN file.

In the old days it used to be LPT1, don't know about now.

No no, that's not how gswin64c works.

BTW, I made a workaround.

From the CGI, instead of calling gswin64c.exe I call the command line program I created for testing and it works as expected. So, it's a shame gswin64c cannot be called from a CGI, but at least this workaround solves the issue.

Here's the DoRun method of the command line program:

Code: Pascal  [Select][+][-]
  1. procedure TMyApplication.DoRun;
  2. var
  3.   lProcess: TProcess;
  4.   lPrinter: string;
  5.   lPaperName: string;
  6.   lFile: string;
  7. begin
  8.   lPrinter := ParamStr(1);
  9.   lPaperName := ParamStr(2);
  10.   lFile := ParamStr(3);
  11.   with TStringList.Create do
  12.   begin
  13.     Add('Printer: ' + lPrinter);
  14.     Add('PaperName: ' + lPaperName);
  15.     Add('File: ' + lFile);
  16.     SaveToFile('params.txt');
  17.     Free;
  18.   end;
  19.   lProcess := TProcess.Create(nil);
  20.   try
  21.     lProcess.Executable:='C:\Program Files\gs\gs9.27\bin\gswin64c.exe';
  22.     lProcess.Options := [poWaitOnExit];
  23.     lProcess.Parameters.Add('-dINITDEBUG');
  24.     lProcess.Parameters.Add('-dNOSAFER');
  25.     lProcess.Parameters.Add('-dNOGC');
  26.     lProcess.Parameters.Add('-dNOPAUSE');
  27.     lProcess.Parameters.Add('-dBATCH');
  28.     lProcess.Parameters.Add('-dDisplayResolution=600');
  29.     lProcess.Parameters.Add('-sPAPERSIZE=a3');
  30.     lProcess.Parameters.Add('-sDEVICE=mswinpr2');
  31.     lProcess.Parameters.Add('-sOutputFile="%printer%' + lPrinter + '"');
  32.     lProcess.Parameters.Add('-sstdout=salida.out');
  33.     lProcess.Parameters.Add('-sstderr=salida.err');
  34.     lProcess.Parameters.Add(lFile);
  35.     lProcess.Execute;
  36.   finally
  37.     lProcess.Free;
  38.   end;
  39.  
  40.   // stop program loop
  41.   Terminate;
  42. end;                                      
  43.  

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Running gswin64c from an Apache CGI on Windows
« Reply #20 on: October 10, 2020, 08:21:42 pm »
That sounds like a permission issue..

Recent windows requires some programs to be elevated before you can run them directly so you do something like is done in Linux and use the "sudo" the CMD basically behaves a lot like it.

 Also the WebBrowser EXE does not like to be ran from much other than the Shell of some windows apps

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018