我正在使用这个node plugin来运行django管理命令。
如果我直接执行命令,它可以工作:
sls wsgi manage local -c "check --list-tags"
如果我调用一个将其作为子进程调用的python脚本,它找不到该命令:
import subprocess
proc = subprocess.Popen(['sls', 'wsgi', 'manage', 'local', '-c', '"check --list-tags"'])
(out, err) = proc.communicate()
"Traceback (most recent call last):\n File \"/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py\", line 102, in call_command\n app_name = get_commands()[command_name]\nKeyError: 'check --list-tags'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"./wsgi_handl
er.py\", line 89, in handler\n management.call_command(*shlex.split(meta.get(\"data\", \"\")))\n File \"/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py\", line 104, in call_command\n raise CommandError(\"Unknown command: %r\" % command_name)\ndjango.core.management.base.CommandError: Unknown command: 'check --list-tags'\n
"
如果我执行的命令不包含任何空格,则可以使用,例如:
subprocess.Popen(['sls', 'wsgi', 'manage', 'local', '-c', '"makemigrations"'])
如果你使用shell = True,你可以将完整的命令作为字符串传递,尝试并稍后进行优化
proc = subprocess.Popen('sls wsgi manage local -c "check --list-tags"' shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)