4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

subprocessでシェルコマンドを呼び出し、標準出力は捨てる(/dev/nullに出力する)

Posted at

環境:Python3

# !/usr/bin/env python3
import subprocess

subprocess.run(['ls', '-l'], stdout=subprocess.DEVNULL)

subprocess.callrunと同じように使えるが、callの方が少し古い。

Python 3.5 より前のバージョンでは、サブプロセスに対して以下の 3 つの関数からなる高水準 API が用意されていました。現在多くの場合 run() の使用で済みますが、既存の多くのコードではこれらの関数が使用されています。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?