2

I am struggling to find out is there a way to feed input to the interactive command of gst a.st b.st ... - and redirect the output. Normally, the interactive buffer will have st> ... and when you type a command it will output something by calling the default/override displayString method to the interactive output. How to get the input and feed the output using linux command or maybe a tiny smalltalk test script to do that. Thank you.

ddttdd
  • 111
  • 1
  • 6
  • 1
    Could you clarify a little more how exactly you want it to work? Do you want to get input from a file instead of entered live from the user? Do you want all the output going to a file? If the prompted input is one line at a time, e.g., using the Stream>>nextLine selector, you can synchronize line inputs from a file with the prompts and not have to get fancy and write a script that matches up prompts with inputs. I recommend `printNl` instead of `displayString` for output to `stdout`. – lurker Feb 25 '21 at 21:43
  • 1
    For the second and third questions, the answer is yes and it is one line at a time. If you could provide a detailed answer on how to use `Stream` with `printNl` as an answer below, it would be helpful, thank you. – ddttdd Feb 26 '21 at 22:05

1 Answers1

1

Here's a contrived demonstration program. It reads in strings from standard input until EOF, sorts them, then prints them out:

input := stdin nextLine.
c := OrderedCollection new.

[ input ~= nil ] whileTrue: [
    c add: input.
    input := stdin nextLine.
].

c sort do: [ :each | each printNl ]

You can run it interactively (pressed Ctrl-D after entering hhh):

$ gst sortprog.st
tttt
aaa
vvvv
hhh
'aaa'
'hhh'
'tttt'
'vvvv'

Or I can create a text file test.in with the following contents:

tttt
aaa
vvvv
hhh

Then run:

$ gst sortprog.st < test.in > test.out

And then check the contents of the output file:

$ cat test.out
'aaa'
'hhh'
'tttt'
'vvvv'

If your program has prompts, they will appear in the output file, of course. Anything going to stdout will go to that file.

lurker
  • 56,987
  • 9
  • 69
  • 103