0

Many command line utilities do certain things and then wait for user input before proceeding further. I was trying one such utility but inside jupyter notebook. But let me give an example of reading variable command. I typed ! read var in jupyter notebook cell, it simply hanged awaiting (with * in front of it) for user input:

enter image description here

The utility I am trying to use in jupyter notebook exhibits same behavior. It executes and then simply hangs for user input with no way to provide a user input to it.

Is it possible to give user input to interactive command line tool when used jupyter notebook? And if yes, how?

PS: I want to do this because its great way to document in jupyter notebook (even full command line utility output).

PS: More common use case will be command line utilities that ask for y/n input. But more complex scenario will be: command line tools / scripts that themselves ask for user input "programatically"? By "programatically", I mean, in some environments, they may ask for one input while in other environment, it might ask for different input.

MsA
  • 2,599
  • 3
  • 22
  • 47
  • 1
    This isn't how you get user input in Jupyter? You use `varname = input()` and Jupyter will pop up an input field when it reaches that line, and then whatever the user submits can be referenced by subsequent lines through that variable. – Mike 'Pomax' Kamermans Jul 15 '23 at 16:10
  • Does this answer your question? [Running interactive command line code from Jupyter notebook](https://stackoverflow.com/questions/44604027/running-interactive-command-line-code-from-jupyter-notebook) – tevemadar Jul 15 '23 at 16:33
  • @Mike'Pomax'Kamermans what about command line tools / scripts that themselves ask for user input "programatically"? By "programatically", I mean, in some environments, they may ask for one input while in other environment, it might ask for different input. More common use case will be command line utilities that ask for y/n input. – MsA Jul 15 '23 at 16:58
  • @tevemadar yup/nope. The highest voted answer there says: "as far as os.system works there is no simple way to know whether the process you will be running will need input from the user". So there is no way to do it? For example, what about command line tools / scripts that themselves ask for user input "programatically"? By "programatically", I mean, in some environments, they may ask for one input while in other environment, it might ask for different input. – MsA Jul 15 '23 at 17:02
  • Why would you use a jupyter notebook for that? That's not even remotely what it's designed for, Jupyter notebooks are loaded using a Jupyter GUI. Using Jupyter to create a CLI tool is like trying to browse a webpage from the command line. Like, not "in a text base browser", but from the command line. Don't use a hammer to screw in a bolt, use the right tool for the job you need to do. Use python with numpy/scipy/etc if you need a CLI-based computational tool? – Mike 'Pomax' Kamermans Jul 15 '23 at 17:46
  • Jupyter notebook seem to be great for writing tutorials demostrating actual code in action. I am not trying to create CLI tool, but trying to show how to use CLI tool in action as a pre-requisite for a setup required for using certain python library. Sometimes its a bit tricky to setup some libraries. Hence, feels better to have everything at one place for a complete tutorial. Consider this same as many commands used in many ML python books, like say downloading nltk dataset. Only thing that it requires some interaction with user. – MsA Jul 16 '23 at 09:09

0 Answers0