Python/サンプル/パイプで渡されたstdinの有無を確認する方法
の編集
Top
/
Python
/
サンプル
/
パイプで渡されたstdinの有無を確認する方法
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * パイプで渡されたstdinの有無を確認する方法 [#a84fedbf] ターミナルからパイプで渡された文字列群があるかどうかを確認するPythonサンプルコードを以下に記します。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 関連記事 [#u29c800c] -[[Rubyでパイプで渡されたstdinの有無を確認する方法>Ruby/サンプル/パイプで渡されたstdinの有無を確認する方法]] * パイプ渡しのstdinの有無確認サンプル [#gd47411c] 以下、Python2, Python3のサンプルコードおよび実行例を記します。 ** Python2向け [#ba007ed2] 使用したPythonは以下の通りです。 $ python --version Python 2.7.9 #ref(ispipe2.py) #!/usr/bin/env python import sys import select def isPipe(): if select.select([sys.stdin,],[],[],0.0)[0]: return True return False if isPipe(): print sys.stdin.readlines() else: print "nothing" 以下、実行したときの出力です。~ パイプ渡しのstdinの有無が確認できていることがわかります。 sakura@debian:~$ chmod +x ispipe2.py sakura@debian:~$ ./ispipe2.py nothing sakura@debian:~$ echo SAKURA | ./ispipe2.py ['SAKURA\n'] ** Python3向け [#g12bca2e] 使用したPython3は以下の通りです。 $ python3 --version Python 3.4.2 #ref(ispipe3.py) #!/usr/bin/env python3 import sys import select def isPipe(): if select.select([sys.stdin,],[],[],0.0)[0]: return True return False if isPipe(): print(sys.stdin.readlines()) else: print("nothing") 以下、実行したときの出力です。~ パイプ渡しのstdinの有無が確認できていることがわかります。 sakura@debian:~$ chmod +x ispipe3.py sakura@debian:~$ ./ispipe3.py nothing sakura@debian:~$ echo SAKURA | ./ispipe3.py ['SAKURA\n'] 以上、Pythonでパイプ渡しのstdinの有無を確認する方法でした。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
タイムスタンプを変更しない
#navi(../) * パイプで渡されたstdinの有無を確認する方法 [#a84fedbf] ターミナルからパイプで渡された文字列群があるかどうかを確認するPythonサンプルコードを以下に記します。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 関連記事 [#u29c800c] -[[Rubyでパイプで渡されたstdinの有無を確認する方法>Ruby/サンプル/パイプで渡されたstdinの有無を確認する方法]] * パイプ渡しのstdinの有無確認サンプル [#gd47411c] 以下、Python2, Python3のサンプルコードおよび実行例を記します。 ** Python2向け [#ba007ed2] 使用したPythonは以下の通りです。 $ python --version Python 2.7.9 #ref(ispipe2.py) #!/usr/bin/env python import sys import select def isPipe(): if select.select([sys.stdin,],[],[],0.0)[0]: return True return False if isPipe(): print sys.stdin.readlines() else: print "nothing" 以下、実行したときの出力です。~ パイプ渡しのstdinの有無が確認できていることがわかります。 sakura@debian:~$ chmod +x ispipe2.py sakura@debian:~$ ./ispipe2.py nothing sakura@debian:~$ echo SAKURA | ./ispipe2.py ['SAKURA\n'] ** Python3向け [#g12bca2e] 使用したPython3は以下の通りです。 $ python3 --version Python 3.4.2 #ref(ispipe3.py) #!/usr/bin/env python3 import sys import select def isPipe(): if select.select([sys.stdin,],[],[],0.0)[0]: return True return False if isPipe(): print(sys.stdin.readlines()) else: print("nothing") 以下、実行したときの出力です。~ パイプ渡しのstdinの有無が確認できていることがわかります。 sakura@debian:~$ chmod +x ispipe3.py sakura@debian:~$ ./ispipe3.py nothing sakura@debian:~$ echo SAKURA | ./ispipe3.py ['SAKURA\n'] 以上、Pythonでパイプ渡しのstdinの有無を確認する方法でした。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
テキスト整形のルールを表示する
添付ファイル:
ispipe2.py
3250件
[
詳細
]
ispipe3.py
589件
[
詳細
]