【发布时间】:2019-01-27 13:29:56
【问题描述】:
问题:
我无法使用 subprocess 从 Python 运行 pdal bash 命令。
这里是代码
基于Running Bash commands in Python:
import os, subprocess
input = '/path/to/file.ply'
output = '/path/to/statfile.json'
if not os.path.isfile(output):
open(output, 'a').close()
bashcmd = ("pdal info --boundary "
+input
+" > "
+output
)
print("Bash command is:\n{}\n".format(bashcmd))
process = subprocess.Popen(bashcommand.split(),
stdout=subprocess.PIPE,
shell=True)
output, error = process.communicate()
print("Output:\n{}\n".format(output))
print("Error:\n{}\n".format(error))
这在 Python 控制台中给了我这个输出:
Bash command is:
pdal info --boundary /path/to/file.ply > /path/to/statfile.json
Output:
Usage:
pdal <options>
pdal <command> <command options>
--command The PDAL command
--debug Sets the output level to 3 (option deprecated)
--verbose, -v Sets the output level (0-8)
--drivers List available drivers
--help, -h Display help text
--list-commands List available commands
--version Show program version
--options Show options for specified driver (or 'all')
--log Log filename (accepts stderr, stdout, stdlog, devnull as
special cases)
--logtiming Turn on timing for log messages
The following commands are available:
- delta
- diff
- fauxplugin
- ground
- hausdorff
- info
- merge
- pcl
- pipeline
- random
- smooth
- sort
- split
- tindex
- translate
See http://pdal.io/apps/ for more detail
Error:
None
它看起来好像只在调用“pdal”之后停止读取命令的参数,这会打印此帮助消息。
如果我复制第一次打印的输出并将其粘贴到 bash 终端,它会正常工作,并为我提供包含所需元数据的输出文件。但是在 Python 中没有创建输出文件。
问题:
我想知道为什么(例如,重定向有什么问题,或者计算本身通常需要大约 20 秒?),以及如何从 Python 执行此命令?
This 没有为当前问题提供足够明确的答案。
【问题讨论】:
标签: python bash subprocess pdal