question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with shell commands (magic) expecting output

See original GitHub issue

This is related (if not identical) to #514 which I don’t understand why was closed (it was not closed with “impossible to fix” or “we don’t have time to fix” which I would understand).

PR #3089 sounds like it has (at least partially) fixed it, but I am not sure it did. I am running ipython v5.3.0 (with jupyter-client v5.0.0 and jupyter-core v4.3.0). This version of ipython has been released after said PR has been merged, so it should be included, however I have not explicitly looked if that code made into into it.

Usual example: the following hangs forever

!(echo "type something"; read foo; echo $foo)

and whatever one types is interpreted as browser shortcut (if applicable) instead of stdin.

Similarly, and perhaps more difficult to fix because of the way ssh handles input for security reasons, this hangs forever too:

!ssh -o StrictHostKeyChecking=no -T username@someserver.com

As far as I’m concerned, it’d be fine if the magic needs to become aware of the need for input, so I’d be ok with having to replace the above commands with something like

%needs_input !(echo "type something"; read foo; echo $foo)

and

%needs_input !ssh -o StrictHostKeyChecking=no -T username@someserver.com

if that simplify the implementation

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
nealmcbcommented, May 7, 2017

This seems related to another common problem: debugging a cell with %pdb on, then forgetting to quit before changing the cell and re-running it. The output the disappears, so you can’t hit “q” any more to quit, and interrupting the kernel doesn’t help. You have to restart the kernel. See e.g. https://github.com/ipython/ipython/issues/3400 which remains open, but which seems different, since it isn’t clear to me that pdb runs a separate sub-process. If there was a way to run pdb on the notebook in a terminal emulator, that would be handy.

0reactions
astrojuanlucommented, Jun 21, 2022

This issue is relatively old but still stands. Seems like there’s not much interest around it though. Have there been any architecture changes to IPython that would make this easier to fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Running shell command and capturing the output
I had the same problem but figured out a very simple way of doing this: import subprocess output = subprocess.getoutput("ls -l") print(output).
Read more >
Expect command and how to automate shell scripts like magic
Learn how to automate shell scripts using expect command, autoexpect, work with variables, conditional tests, while loops, for loops, ...
Read more >
Built-in magic commands — IPython 8.7.0 documentation
Shell execute - run shell command and capture output (!! is short-hand). %sx command. IPython will run the given command using commands.getoutput(), and...
Read more >
expect: Scripts for Controlling Interactive Processes
fsck, the UNIX file system check program, can be run from a shell script only with the –y or –n ... es and...
Read more >
Advanced Bash-Scripting Guide
Piping the output of echo to a read; 36-1. shell wrapper; 36-2. ... If a script expects a command-line parameter but is invoked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found