protobuf 爬坑记

最近,在写一个C#版本的protoc转换工具,发现死活转不出来,报各种奇奇怪怪的错误,如missing input file等。不得不说,win版本的protoc设计很烂~~,先贴教程里唯一提到的一行:

protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/addressbook.proto

命令行下,$SRC_DIR是 ".proto"文件所在目录,$DST_DIR是输出目录,最后是$SRC_DIR/xx.proto,要严格遵循这种参数格式,才能指定绝对路径。

 var file = Path.GetFullPath(textBox1.Text);
                        var fileName = Path.GetFileName(file);
                        var workDir = file.Replace(fileName,"");
                        string src = textBox1.Text;
                        string outPath = textBox3.Text;
                        string args = string.Format("-I {0} --csharp_out {1} {2}",workDir,outPath,file);
                        // 运行新进程
                        Process process = new Process();

                        process.StartInfo.FileName = _complilerPath;

                        process.StartInfo.UseShellExecute = false;   // 是否使用外壳程序 

                        process.StartInfo.CreateNoWindow = true;   //是否在新窗口中启动该进程的值 

                        process.StartInfo.RedirectStandardInput = true;  // 重定向输入流 
                        process.StartInfo.WorkingDirectory = Application.StartupPath;
                        process.StartInfo.RedirectStandardOutput = true;  //重定向输出流 

                        process.StartInfo.RedirectStandardError = true;  //重定向错误流 
                        process.StartInfo.Arguments = args;
                     
                        process.Start();
                        string error = process.StandardOutput.ReadToEnd();//获取输出信息 
                        error = process.StandardError.ReadToEnd();//获取输出信息 
                        if(!string.IsNullOrEmpty(error))
                        {
                            listView1.Items.Add("[Error]"+error);
                        }
                        process.WaitForExit();
                        process.Close();
                        listView1.Items.Add(file);
                        listView1.Items.Add("转换完毕!");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值