Loading ...
Sorry, an error occurred while loading the content.

How to get user input via the command line?

Expand Messages
  • Guilherme
    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
    Message 1 of 2 , Nov 2, 2011
    • 0 Attachment
      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.
    • Russell Allen
      Hi Guilherme, ... If you are on the command line, then: What is your name? print. ( Hello, , (stdin readLine) printLine. should do it. print and printLine
      Message 2 of 2 , Nov 2, 2011
      • 1 Attachment
      • 19 KB
      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
    Your message has been successfully submitted and would be delivered to recipients shortly.