【发布时间】:2016-12-21 19:21:14
【问题描述】:
我在 gulp 中重写了一些 bash 代码,这些代码为不同的浏览器生成了几个附加组件/扩展,灵感来自 GitHub 上的 ublockorigin 项目。
对于 Firefox,有一行代码应该运行一个以目标目录作为参数的 python 脚本。在 gulp 中,我很难运行这个 python 脚本。
我尝试了gulp-run、gulp-shell、child_process,但它们都没有给我正确的输出。
当我从命令行运行python ./tools/make-firefox-meta.py ../firefox_debug/ 时,我得到了我想要的结果并创建了firefox_debug 目录。
这是我的gulp-run 代码:
gulp.task("python-bsff", function(){
return run("python ./tools/make-firefox-meta.py ../firefox_debug/").exec();
});
这是给了我这个而实际上没有做任何事情:
$ gulp python-bsff
[14:15:53] Using gulpfile ~\dev\gulpfile.js
[14:15:53] Starting 'python-bsff'...
[14:15:54] Finished 'python-bsff' after 629 ms
$ python ./tools/make-firefox-meta.py ../firefox_debug/
这是我的gulp-shell 代码:
gulp.task("python-bsff", function(){
return shell.task(["./tools/make-firefox-meta.py ../firefox_debug/""]);
});
这给了我这个没有实际结果:
$ gulp python-bsff
[14:18:54] Using gulpfile ~\dev\gulpfile.js
[14:18:54] Starting 'python-bsff'...
[14:18:54] Finished 'python-bsff' after 168 μs
这是我为child_process 编写的代码:这是最有前途的代码,因为我在命令行上看到了 python 的一些输出。
gulp.task("python-bsff", function(){
var spawn = process.spawn;
console.info('Starting python');
var PIPE = {stdio: 'inherit'};
spawn('python', ["./tools/make-firefox-meta.py `../firefox_debug/`"], PIPE);
});
它给了我这个输出:
[14:08:59] Using gulpfile ~\dev\gulpfile.js
[14:08:59] Starting 'python-bsff'...
Starting python
[14:08:59] Finished 'python-bsff' after 172 ms
python: can't open file './tools/make-firefox-meta.py ../firefox_debug/`': [Errno 2] No such file or directory
谁能告诉我,我应该做些什么改变才能让它工作?
【问题讨论】:
标签: python gulp firefox-addon child-process gulp-shell