LoginSignup
0
1

More than 5 years have passed since last update.

python2と3のそれぞれでosコマンドを実行してその結果を取得する

Posted at

いずれもsubprocessを使用します。
する……んですが、3から2に落とすっていう不思議な作業をしていたらちょっと戸惑ってしまったので。

python2.py
import subprocess

result = subprocess.check_output(["ls", "-l"])
print(result)
python3.py
import subprocess

process_result = subprocess.run(["ls", "-l"], stdout=subprocess.PIPE)
result = process_result.stdout.decode('ascii')

print(result)

早く全部3で記述できる世の中にならないかしら

0
1
1

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
0
1