【发布时间】:2019-10-07 15:17:38
【问题描述】:
我想检查一个文件的格式是否正确
command_process = subprocess.Popen('black -q
file_utils.py'.split(' '), stdout=subprocess.PIPE)
subprocess.run(['diff', '-q', 'file_utils.py'],
stdin=command_process.stdout, stdout=subprocess.PIPE, universal_newlines=True)
上面的命令出现以下错误
diff: missing operand after `file_utils.py'
diff: Try `diff --help' for more information.
CompletedProcess(args=['diff', '-q', 'file_utils.py'], returncode=2, stdout='')
【问题讨论】:
-
不要使用
str.split;它不遵循 shell 语法规则。手动构建列表,或使用shlex.split。
标签: python subprocess