[self-interest] How to get user input via the command line?

Russell Allen mail at russell-allen.com
Wed Nov 2 23:35:09 UTC 2011


Hi Guilherme,

On Wed, 02 Nov 2011 15:40:50 -0000, Guilherme wrote:
> In some posts, some have suggested using the "userQuery askString:
> 'Your name?' " command, but could not implement it. Can you show me a
> code that gets the user name, which he advises, and then prints it on
> screen?
> (No need to use the Morphic, only the command line.)
> 
> Thank You.

If you are on the command line, then:

'What is your name? print.
('Hello, ', (stdin readLine) printLine.

should do it.  print and printLine currently by default print to stdout.

The only tricky bit is that the prompt (repl) is reading and writing at the same time as you are, so it could steal some of your input or write over some of your output. It is best to suspend the prompt's process while you are using stdin.

If you file in the attached by doing 'path/to/prompt.self' runScript , you should then be able to do

prompt suspendWhile: [ stdin readLine printLine ]

which should do what you want. Let us know how you go...

Cheers, Russell


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/x-ygp-stripped
Size: 166 bytes
Desc: not available
URL: <http://lists.selflanguage.org/pipermail/self-interest/attachments/20111103/e1a41bfc/attachment.bin>


More information about the Self-interest mailing list