[英]How to use text file as input to feed in the interactive input of smalltalk and redirect output to a file
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.我正在努力找出是否有办法将输入提供给
gst a.st b.st... -
并重定向 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.通常,交互式缓冲区将具有
st>...
并且当您键入命令时,它会通过调用交互式 output 的默认/覆盖displayString
方法来实现 output 。 How to get the input and feed the output using linux command or maybe a tiny smalltalk test script to do that.如何获取输入并使用 linux 命令或可能是一个小的 smalltalk 测试脚本来提供 output。 Thank you.
谢谢你。
Here's a contrived demonstration program.这是一个人为的演示程序。 It reads in strings from standard input until EOF, sorts them, then prints them out:
它从标准输入中读取字符串直到 EOF,对它们进行排序,然后将它们打印出来:
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
):您可以交互地运行它(输入
hhh
后按 Ctrl-D ):
$ gst sortprog.st
tttt
aaa
vvvv
hhh
'aaa'
'hhh'
'tttt'
'vvvv'
Or I can create a text file test.in
with the following contents:或者我可以创建一个包含以下内容的文本文件
test.in
:
tttt
aaa
vvvv
hhh
Then run:然后运行:
$ gst sortprog.st < test.in > test.out
And then check the contents of the output file:然后查看output文件的内容:
$ cat test.out
'aaa'
'hhh'
'tttt'
'vvvv'
If your program has prompts, they will appear in the output file, of course.如果你的程序有提示,当然会出现在 output 文件中。 Anything going to
stdout
will go to that file.任何进入
stdout
的内容都会 go 到该文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.