1
0

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 1 year has passed since last update.

pythonのsubprocessでコマンド実行

Last updated at Posted at 2021-12-17

subprocessでコマンド実行結果を取得

以下で取れます。

import subprocess
res = subprocess.run("whoami", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) 

print(res.returncode) #=> 終了コード
print(res.stdout)  #=> 標準出力
print(res.stderr) #=> 標準エラー出力

以上です。

※以下、どうでもいいこと。

「こんにちは! IT業界3日目の初心者プログラマーです! 」みたいな入りやめませんか。
「こんにちは! IT業界3日目の初心者プログラマーです! 今日はosのカーネル解析をしてみました!」みたいな。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?