首页 新闻 会员 周边

c# 怎么模拟键盘输入 字符串到 git-bash.exe. (输入命令到cmd.exe我是实现了的)

0
悬赏园豆:10 [已解决问题] 解决于 2016-05-30 19:58

 1. cmd.exe的模拟输入,成功的

 

  Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = cmdExe; // "cmd.exe";//要启动的应用程序;
                p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;//true //不显示程序窗口
                p.Start();//启动程序

                //#2. 向cmd窗口发送输入信息
                p.StandardInput.WriteLine(command + "&exit");
                p.StandardInput.AutoFlush = true;
             //#3. 获取cmd窗口的输出信息

                //1.ReadtoEnd()容易卡住,更倾向于使用ReadLine();
                //string output = p.StandardOutput.ReadToEnd();

                StreamReader reader = p.StandardOutput;
                string line = reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    output += line + "  ";
                    line = reader.ReadLine();
                }

                p.WaitForExit();//等待程序执行完退出进程
                p.Close();

 

2. git-bash.exe的模拟输入,失败的

 

                Process vProcess = Process.Start(D:\\Program Files\\Git\\git-bash.exe);
                while (vProcess.MainWindowHandle == IntPtr.Zero) vProcess.Refresh();

                IntPtr vHandle = FindWindowEx(vProcess.MainWindowHandle,
                    IntPtr.Zero, "Edit", null);
                SendMessage(vHandle, WM_SETTEXT, 0, "Zswang 路过");

 

 

 

 

sicnu-yudidi的主页 sicnu-yudidi | 初学一级 | 园豆:108
提问于:2016-05-30 11:15
< >
分享
最佳答案
0

git-bash 不接受进程消息传输。

收获园豆:10
Hoze | 初学一级 |园豆:196 | 2016-05-30 11:26

 哦哦,原来是这样。谢谢大神。能够请问哈,调用git api 可以在代码完成项目的上传,远程仓库的创建工作吗?

sicnu-yudidi | 园豆:108 (初学一级) | 2016-05-30 13:38

@原始滴滴: Git和github都有Windows专用的客户端,如果自己写上传和检出的话,可以参考https://developer.github.com/v3/

Hoze | 园豆:196 (初学一级) | 2016-05-30 17:06

@原始滴滴: Git:https://git-for-windows.github.io/

git hub:https://desktop.github.com/

Hoze | 园豆:196 (初学一级) | 2016-05-30 17:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册