0
1

シェルスクリプトからPythonを呼び出して戻り値を受け取る

Posted at

シェルスクリプトからPythonを呼び出して戻り値を受け取りたい

sys.stdout.write()で戻り値として受け取れる

result.py
import sys
sys.stdout.write("hoge")
call.sh
result=$(python result.py)
echo $result
実行結果
hoge

おまけ

複数sys.stdout.write()を書くと

result.py
import sys
sys.stdout.write("hoge")
sys.stdout.write("fuga")
sys.stdout.write("piyo")

全部返ってくるので、欲しい値だけ返そう

実行結果
hogefugapiyo
0
1
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
0
1