How to use text file as input to feed in the interactive input of smalltalk and redirect output to a file

292 Views Asked by At

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.

1

There are 1 best solutions below

0
lurker On BEST ANSWER

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.