Difficulty using subprocess

45 views
Skip to first unread message

Brian Adkins

unread,
Nov 15, 2018, 1:51:40 PM11/15/18
to Racket Users
I'm porting a Ruby application to Racket (will be deployed on Linux, but I'm developing on OSX). It uses the s3270 terminal emulator to access a mainframe. An example in Ruby is:

IO.popen('s3270 L:ssl3270.example.com:2023', 'r+') do |pipe|
  pipe.puts "ascii"
  puts (pipe.gets)
  puts (pipe.gets)
end

That issues the "ascii" command, and then reads & displays 2 lines of output. It seems that Racket's subprocess is a reasonable choice for this, so I tried the following:

(define-values (subp inp outp errp) 
  (subprocess #f #f #f "/usr/local/bin/s3270" "L:ssl3270.example.com:2023"))
(displayln "ascii" outp)
(displayln (read-line inp))
(displayln (read-line inp))

It seems to be connecting to the mainframe because I got a request from Little Snitch to allow the outbound connection. The s3270 emulator behaves similar to telnet, if I invoke the command in a shell, the program will start, then I'll enter ascii and it will display a screenful of lines. I must be misunderstanding subprocess or the associated IO functions. Any suggestions?

Thanks,
Brian


Philippe Mechaï

unread,
Nov 15, 2018, 2:02:07 PM11/15/18
to Brian Adkins, Racket Users
Hi Brian

I think you need to add a call to flush-output after sending data to outp 

Regards
Philippe 


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Adkins

unread,
Nov 15, 2018, 2:07:37 PM11/15/18
to Racket Users
That was it - thanks! I guess I was spoiled by Ruby's auto-flushing of "puts".

Philip McGrath

unread,
Nov 15, 2018, 2:50:33 PM11/15/18
to lojic...@gmail.com, racket...@googlegroups.com
You can also use `file-stream-buffer-mode` instead of manually flushing the port: https://docs.racket-lang.org/reference/port-buffers.html#(def._((quote._~23~25kernel)._file-stream-buffer-mode))

-Philip

Brian Adkins

unread,
Nov 15, 2018, 3:07:44 PM11/15/18
to Racket Users
Good tip - I think (file-stream-buffer-mode outp 'line) makes sense in this case given it's a terminal emulator.
Reply all
Reply to author
Forward
0 new messages