簡體   English   中英

執行shell命令並在Jupyter中使用它的輸出

[英]Execute shell command and use it's output in Jupyter

我知道這是一個經常性的問題,但我找不到有用的答案。

在Python中,運行shell命令可以使用this

如果我在Jupyter中執行相同的操作,則無輸出。 如何查看執行命令的結果? 在做

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

返回零。

使用! 貝殼魔術:

!ping -c 2 www.cyberciti.biz

如果要將其分配給變量:

output = !ping -c 2 www.cyberciti.biz
print(output)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM