Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized commands in bash are captured by the python interpreter [closed]

Tags:

python

bash

Every time I try to invoke a command that does not exist ($ a, for example) in the console (/bin/bash) the interpreter waits for a long time. And when I interrupt it (^C), I get a error message from Python interpreter. Instead of that, I expect it to tell me that the command was unrecognized. Why is this happening?

$ a
^C
Traceback (most recent call last):
  File "/usr/lib/python2.7/encodings/__init__.py", line 32, in <module>
root@dell:/home/antonio/workspace/biz_index#     from encodings import aliases
  File "/usr/lib/python2.7/encodings/aliases.py", line 17, in <module>
    """
KeyboardInterrupt
^C
like image 528
Antonio Romero Oca Avatar asked May 12 '15 07:05

Antonio Romero Oca


People also ask

Can you run bash commands in Python?

Execute an existing bash script using Python subprocess module. We can also execute an existing a bash script using Python subprocess module.

How do you execute a shell command in python and get output?

Running shell commands: the shell=True argument Both with check_output() and communicate() you have to wait until the process is done, with poll() you're getting output as it comes.

How do I run a shell script in Python?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!


1 Answers

Are you on an ubuntu machine? Ubuntu has a command-not-found package which is implemented in python, you may have interrupted that.

In your path, there may be a script with the same name as one called by the command-not-found package. If there is, this script is likely the one doing the hanging. To print your path in a readable way, run echo $PATH | tr -s ':' '\n'.

like image 89
EvenLisle Avatar answered Sep 21 '22 19:09

EvenLisle