Discussion:
socat / ghostscript questions
James B. Byrne via freebsd-questions
2021-04-20 15:51:20 UTC
Permalink
I am trying to produce pdf files using socat and ghostscript. I have this
command for socat:

socat TCP4-LISTEN:9100,bind=192.168.216.41,fork,reuseaddr SYSTEM:'gs -dQUIET
-dNOPROMPT -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/\"$(date
-Iseconds)\".pdf -'


Which I try to send a text file to using cat and nc:

cat sshpipe3.txt | nc 192.168.216.41 9100


What happens is that the cat/nc pipe hangs. This is probably an artifact of
how nc works but I need to check that is so. When I terminate nc with <ctrl>-c
the socat gs instance reports an error:

GPL Ghostscript 9.52: Unrecoverable error, exit code 1
2021/04/20 11:32:51 socat[67296] E write(6, 0x800adf000, 128): Broken pipe

This produces an empty file named like /tmp/2021-04-20T11:13:20-04:00.pdf.

I am no doubt missing the obvious here so I have a few naive questions:

1. Is it possible to terminate the sending process without causing GS to issue
an error?

2. Would printing from another host to that socat instance result in the same
broken pipe error?

3. Why are the files that gs creates empty?

4. How do I send a text file to the socat instance so that it is converted to a
pdf document?
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Unencrypted messages have no legal claim to privacy
Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne mailto:***@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
James B. Byrne via freebsd-questions
2021-04-20 16:05:40 UTC
Permalink
Post by James B. Byrne via freebsd-questions
3. Why are the files that gs creates empty?
A. Because ghostscript expects a .ps file. So I changed cat to enscript and
that produces pdfs.
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Unencrypted messages have no legal claim to privacy
Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne mailto:***@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
Paul Procacci
2021-04-20 16:17:32 UTC
Permalink
The hang is most likely because an EOF doesn't get trasmitted over the wire.
Adding a timeout I believe should fix the problem.

nc -w 1 [addr] [port] < filename.txt

On Tue, Apr 20, 2021 at 11:51 AM James B. Byrne via freebsd-questions <
Post by James B. Byrne via freebsd-questions
I am trying to produce pdf files using socat and ghostscript. I have this
socat TCP4-LISTEN:9100,bind=192.168.216.41,fork,reuseaddr SYSTEM:'gs -dQUIET
-dNOPROMPT -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/\"$(date
-Iseconds)\".pdf -'
cat sshpipe3.txt | nc 192.168.216.41 9100
What happens is that the cat/nc pipe hangs. This is probably an artifact of
how nc works but I need to check that is so. When I terminate nc with <ctrl>-c
GPL Ghostscript 9.52: Unrecoverable error, exit code 1
2021/04/20 11:32:51 socat[67296] E write(6, 0x800adf000, 128): Broken pipe
This produces an empty file named like /tmp/2021-04-20T11:13:20-04:00.pdf.
1. Is it possible to terminate the sending process without causing GS to issue
an error?
2. Would printing from another host to that socat instance result in the same
broken pipe error?
3. Why are the files that gs creates empty?
4. How do I send a text file to the socat instance so that it is converted to a
pdf document?
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Unencrypted messages have no legal claim to privacy
Do NOT open attachments nor follow links sent by e-Mail
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "
--
__________________

:(){ :|:& };:
Arthur Chance
2021-04-20 16:23:58 UTC
Permalink
Post by Paul Procacci
The hang is most likely because an EOF doesn't get trasmitted over the wire.
Adding a timeout I believe should fix the problem.
nc -w 1 [addr] [port] < filename.txt
Better to use the -N flag.

-N shutdown(2) the network socket after EOF on the input. Some
servers require this to finish their work.
Post by Paul Procacci
On Tue, Apr 20, 2021 at 11:51 AM James B. Byrne via freebsd-questions <
Post by James B. Byrne via freebsd-questions
I am trying to produce pdf files using socat and ghostscript. I have this
socat TCP4-LISTEN:9100,bind=192.168.216.41,fork,reuseaddr SYSTEM:'gs -dQUIET
-dNOPROMPT -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/\"$(date
-Iseconds)\".pdf -'
cat sshpipe3.txt | nc 192.168.216.41 9100
What happens is that the cat/nc pipe hangs. This is probably an artifact of
how nc works but I need to check that is so. When I terminate nc with <ctrl>-c
GPL Ghostscript 9.52: Unrecoverable error, exit code 1
2021/04/20 11:32:51 socat[67296] E write(6, 0x800adf000, 128): Broken pipe
This produces an empty file named like /tmp/2021-04-20T11:13:20-04:00.pdf.
1. Is it possible to terminate the sending process without causing GS to issue
an error?
2. Would printing from another host to that socat instance result in the same
broken pipe error?
3. Why are the files that gs creates empty?
4. How do I send a text file to the socat instance so that it is converted to a
pdf document?
--
Lebowskisort, aka dudesort, an O(1) sorting algorithm:

"Man, the array is cool as it is. Let's go bowling."
Paul Procacci
2021-04-20 16:28:59 UTC
Permalink
I tested the N flag and it resulted in some sort of stack trace; I didn't
go into it that deeply and may have been easy to fix. /shrug
Post by Arthur Chance
Post by Paul Procacci
The hang is most likely because an EOF doesn't get trasmitted over the
wire.
Post by Paul Procacci
Adding a timeout I believe should fix the problem.
nc -w 1 [addr] [port] < filename.txt
Better to use the -N flag.
-N shutdown(2) the network socket after EOF on the input. Some
servers require this to finish their work.
Post by Paul Procacci
On Tue, Apr 20, 2021 at 11:51 AM James B. Byrne via freebsd-questions <
Post by James B. Byrne via freebsd-questions
I am trying to produce pdf files using socat and ghostscript. I have
this
Post by Paul Procacci
Post by James B. Byrne via freebsd-questions
socat TCP4-LISTEN:9100,bind=192.168.216.41,fork,reuseaddr SYSTEM:'gs -dQUIET
-dNOPROMPT -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/\"$(date
-Iseconds)\".pdf -'
cat sshpipe3.txt | nc 192.168.216.41 9100
What happens is that the cat/nc pipe hangs. This is probably an
artifact
Post by Paul Procacci
Post by James B. Byrne via freebsd-questions
of
how nc works but I need to check that is so. When I terminate nc with <ctrl>-c
GPL Ghostscript 9.52: Unrecoverable error, exit code 1
2021/04/20 11:32:51 socat[67296] E write(6, 0x800adf000, 128): Broken
pipe
Post by Paul Procacci
Post by James B. Byrne via freebsd-questions
This produces an empty file named like
/tmp/2021-04-20T11:13:20-04:00.pdf.
Post by Paul Procacci
Post by James B. Byrne via freebsd-questions
1. Is it possible to terminate the sending process without causing GS to issue
an error?
2. Would printing from another host to that socat instance result in the same
broken pipe error?
3. Why are the files that gs creates empty?
4. How do I send a text file to the socat instance so that it is
converted
Post by Paul Procacci
Post by James B. Byrne via freebsd-questions
to a
pdf document?
--
"Man, the array is cool as it is. Let's go bowling."
--
__________________

:(){ :|:& };:
James B. Byrne via freebsd-questions
2021-04-20 16:46:52 UTC
Permalink
Post by Arthur Chance
Post by Paul Procacci
The hang is most likely because an EOF doesn't get trasmitted over the wire.
Adding a timeout I believe should fix the problem.
nc -w 1 [addr] [port] < filename.txt
Better to use the -N flag.
-N shutdown(2) the network socket after EOF on the input. Some
servers require this to finish their work.
That worked for me. Thanks.


$ enscript -p - t2.txt | nc -N 192.168.216.41 9100
[ 1 page * 1 copy ] left in -
1 line was wrapped
$
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Unencrypted messages have no legal claim to privacy
Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne mailto:***@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
Loading...