Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows上运行protobuf python插件_Python_Windows_Protocol Buffers - Fatal编程技术网

如何在Windows上运行protobuf python插件

如何在Windows上运行protobuf python插件,python,windows,protocol-buffers,Python,Windows,Protocol Buffers,我目前正在使用Protobuf插件生成一些定制的C#代码,给定一组Protobuf文件。它在Linux上运行良好,我也希望在Windows上运行它,以便直接从我的VisualStudio项目生成此代码 以下是我当前(未成功)使用的命令行: path\to\protoc.exe --plugin=protoc-gen-my-plugin=path\to\my-plugin.py --my-plugin_out=output\path\gen my_proto.proto 下面是我得到的错误: -

我目前正在使用Protobuf插件生成一些定制的C#代码,给定一组Protobuf文件。它在Linux上运行良好,我也希望在Windows上运行它,以便直接从我的VisualStudio项目生成此代码

以下是我当前(未成功)使用的命令行:

path\to\protoc.exe --plugin=protoc-gen-my-plugin=path\to\my-plugin.py --my-plugin_out=output\path\gen my_proto.proto
下面是我得到的错误:

--my-plugin_out:protoc gen my plugin:%1未通过统一应用程序Win32 valide

我已经安装了Python2.7.11,它在我的路径中。我还尝试使用x86和x64可执行文件运行protoc.exe


是否有我不知道或遗漏的限制?

我能够通过将python插件封装在.bat文件中来修复我的问题。以下是我使用的代码:

@echo off
chdir path\to\my-plugin
python -u my-plugin.py
运行python脚本时的“-u”选项非常重要,因为否则标准输入将被缓冲。由于protoc通过stdin将所有输入传递给插件(要解析的.proto文件),这一点非常重要。输出由插件写入标准输出,因此没有问题

下面是使用我的插件执行protoc的最后一个命令:

path\to\protoc.exe --plugin=protoc-gen-my-plugin=redirect.bat --my-plugin_out=output\path\gen my_proto.proto