0

I know this is a recurrent question, but I can't find a useful answer.

In Python, for running a shell command one can use this.

If I do the same inside Jupyter I got no output. How can I see the results of executing the command? Doing

print subprocess.call(["ping", "-c 2", "www.cyberciti.biz"])

returns zero.

1
  • Running shell commands requires access to the OS running the Python script. Scripts in Jupyter are probably denied that access for security reasons. Commented Sep 20, 2018 at 18:49

1 Answer 1

5

Use the ! shell magic:

!ping -c 2 www.cyberciti.biz

If you want to assign it to a variable:

output = !ping -c 2 www.cyberciti.biz
print(output)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.