简体   繁体   English

如何使用文本文件作为输入来输入 smalltalk 的交互式输入并将 output 重定向到文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM