LoginSignup
14
12

More than 5 years have passed since last update.

subprocess.callの実行時エラー対処方法

Last updated at Posted at 2016-07-24

発生事象

【スタダ】ポケモンGOがリリースされたら電話掛かってくるスクリプト
上の記事を丸パクリしてスクリプトをcron実行させようとした時に
pythonのsubprocessモジュールでコマンド実行時に以下のエラーが発生

python poke_check.py 
Traceback (most recent call last):
  File "poke_check.py", line 47, in <module>
    start()
  File "poke_check.py", line 43, in start
    subprocess.call("echo 'not open'")
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

原因・解決策

上記のstackoverflowの記事により解決。

実行したいコマンドを文字列で渡す場合はフラグが必要みたい。

subprocess.call("(実行したいコマンド)", shell=True)
14
12
2

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
14
12