Python script as a compiler plugin

84 views
Skip to first unread message

Ralf

unread,
Aug 5, 2010, 9:26:05 AM8/5/10
to Protocol Buffers
For my J2ME port, I used the compiler plugin system introduced in
protobuf 2.3.0. It really simplified my work - the entire code
generator is only about 200 lines of Python code, and another 160
lines for the template (see http://github.com/ponderingpanda/protobuf-j2me/tree/master/generator/).

To be able to use the script to generate code, it must have the name
"protoc-gen-xxx". To do this on Linux is simple - I can either make my
Python script executable and place it in the system path, or I can
create a shell script that simply runs the Python script, for example:

#!/bin/sh
cd path/to/script
python thescript.py

However, I have no idea how to do the same in Windows. I couldn't get
it to work using batch files - I think it breaks the standard input/
output.

Do you have any suggestions on how to run a Python script in Windows
with protoc?

Ralf

Sean Lin

unread,
Aug 8, 2010, 12:14:27 PM8/8/10
to Protocol Buffers
Write a Bat to run python script.
Use this command

protoc --plugin=protoc-gen-j2me=path/to/protoc-gen-j2me.bat --
j2me_out=output-path your.proto

On Aug 5, 9:26 pm, Ralf <ralf.kist...@gmail.com> wrote:
> For my J2ME port, I used the compiler plugin system introduced in
> protobuf 2.3.0. It really simplified my work - the entire code
> generator is only about 200 lines of Python code, and another 160
> lines for the template (seehttp://github.com/ponderingpanda/protobuf-j2me/tree/master/generator/).

Kenton Varda

unread,
Aug 10, 2010, 5:50:59 PM8/10/10
to Ralf, Protocol Buffers
On Thu, Aug 5, 2010 at 6:26 AM, Ralf <ralf.k...@gmail.com> wrote:
However, I have no idea how to do the same in Windows. I couldn't get
it to work using batch files - I think it breaks the standard input/
output.

Could you explain this more?  Batch files should be the correct approach on Windows.

Ralf Kistner

unread,
Aug 12, 2010, 5:19:10 AM8/12/10
to Kenton Varda, Protocol Buffers
For example when not using "@echo off", the batch file adds its own
output to standard out.

I'll have to look into this again, perhaps it could work.

Ralf

Reply all
Reply to author
Forward
0 new messages