バッチファイルとpythonプログラムの間の接続を構築したい。
Pythonを使用して「abc」というパラメーターを取得し、バッチファイルでパラメーター「abc」を使用して他のことを行いたいと考えています。
Python でコマンドラインにパラメータを返すにはどうすればよいですか?
ご協力いただきありがとうございます。
バッチファイルとpythonプログラムの間の接続を構築したい。
Pythonを使用して「abc」というパラメーターを取得し、バッチファイルでパラメーター「abc」を使用して他のことを行いたいと考えています。
Python でコマンドラインにパラメータを返すにはどうすればよいですか?
ご協力いただきありがとうございます。
使用している環境 (* nix/Windows/OSX など) は言いませんが、* nix およびシェルスクリプトの場合は実行できます
# Python
# whatever.py
import sys
sys.stdout.write('abc')
sys.exit(0)
# In your shell
OUT=`python whatever.py`
echo $OUT
# Will print abc, and it's stored in the variable `OUT` for later consumption.
編集 (Windows の場合):
# Python
# whatever.py
import sys
sys.stdout.write('abc')
sys.exit(0)
# In a .bat file, or cli.
python whatever.py > temp.txt
set /p OUT=<temp.txt
# Creates/replaces a file called temp.txt containing the output of whatever.py
# then sets the `OUT` var with the contents of it.
残念ながら、Windows の方法は、*nix の方法ほど適切ではありません。