我试图用python构建一些文件,但是它以错误的方式执行它。你知道吗
我试着在linux中构建一些文件。
当我在终端中使用“make ./package/feeds/proj/{clean,compile} V=s
”命令时,它工作正常,但是当我尝试用python脚本运行它时,使用命令“p = subprocess.call(r'/usr/bin/make package/feeds/proj/{clean,compile} V=s',shell = True))
”,它的行为不同。你知道吗
日志:
试运行终端时:
make[1]: Entering directory '/local/mnt/workspace/rubaeshk/unused2/qsdk'
make[2]: Entering directory '/local/mnt/workspace/rubaeshk/unused2/qsdk/package/feeds/whc/qca-whc-crash-log'
rm -f /local/mnt/workspace/rubaeshk/unused2/qsdk/bin/ipq/packages/whc/qca-whc-crash-log_*
..(log continued until successfully built)
运行python脚本时:
WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!
make[1]: Entering directory '/local/mnt/workspace/rubaeshk/unused2/qsdk'
make[1]: *** No rule to make target 'package/feeds/whc/qca-whc-crash-log/{clean,compile}'. Stop.
make[1]: Leaving directory '/local/mnt/workspace/rubaeshk/unused2/qsdk'
/local/mnt/workspace/rubaeshk/unused2/qsdk/include/toplevel.mk:186: recipe for target 'package/feeds/whc/qca-whc-crash-log/{clean,compile}' failed
make: *** [package/feeds/whc/qca-whc-crash-log/{clean,compile}] Error 2
有人能看出哪里出了问题吗。。你知道吗
Brace扩展不是标准shell的一部分;它是一些shell(比如bash)在POSIX之外提供的附加功能。当你跑的时候子流程调用在Python中,它可能使用
/bin/sh
,而不是/bin/bash
。你知道吗所以,写出来:
package/feeds/whc/qca-whc-crash-log/clean package/feeds/whc/qca-whc-crash-log/compile
正如在^{} documentation (
subprocess.call
委托给Popen
中所解释的,与所有其他方便函数一样,subprocess.call('command', shell=True)
在Unix中等同于运行argv:而且
sh
不支持大括号扩展(这是{a,b}
语法的正式名称)。你知道吗要使用
bash
运行命令,需要重写与executable
参数一起使用的shell可执行文件:示例:
但是请注意,不鼓励使用
shell=True
,因为它本身是特定于平台的,依赖于本地shell及其设置,如果使用不受信任的输入,则可能是一个bug或安全漏洞。最好手动构造命令行并传递结果argv。相关问题 更多 >
编程相关推荐