做项目时候,想在cmd 用subversion 的命令行 做不同版本的比较并写入文件。
具体命令如下:
myprocess.StandInput.Writeline(svn diff -r 9:10 >> c:\dd.txt);
想用c#调用cmd 命令,但是含有参数,结果命令老是不能执行.
具体命令如下:
myprocess.StandInput.Writeline(svn diff -r 9:10 >> c:\dd.txt);
想用c#调用cmd 命令,但是含有参数,结果命令老是不能执行.
解决方案 »
- Dev控件问题,求教,很急
- 拖拽层怎样保存DIV状态到数据库中?
- 能不能用c#开发连接远程桌面将本地文件传输到服务器上?(送100分)
- 参数化查询中参数在in中改怎么处理
- 一对多问题。急急急急急急急急急急急急急
- List.FindAll()的方法消耗很多内存,而且令w3wp进程假死
- C#安装问题:无法创建WEB开发.
- 共同学习,共同进步!!!!欢迎志同道合的朋友加盟,群号14538020:(VB.NET);群号14149080:(C#.NET)
- 统计一下,WEB开发用C#还是VB?
- 小问题!无边框窗体为何最小化时五图标?如何显示图标?来者有分...分可加,先给真么多
- C#如何为tabpage设置背景图片?????急啊!!!!!!!!!!!!!!!!!!
- 用C#做五笔打字软件怎么实现编码提示?
不知道你初始化OK了没
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "cmd.exe";//开启CMD
process.Start();//执行
process.StandardInput.WriteLine(cmd命令字符串);
process.StandardInput.WriteLine("\r\nexit");//这是退出
process.Close();
process.Dispose();
希望能帮到您
因为我有执行其他命令,都是成功了的。
出错是执行命令的时候带了个参数,
因此在c#里面调用的时候,就执行不了。
郁闷!
> x.txt不好使的话可以试一下
2> x.txt也许可以解决问题
或许真的是命令不支持吧。
但是
svn diff -r 1:2 >c:\1.txt ?
真的无解了吗?
有没有使用过subversion的高手教教我啊!
不要太让我失望了阿!!!
svn diff -r 1:2 > c:\1.txt ? 等命令放到批处理文件里面,再由C#实现代码调用该批处理文件。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace svnmirror
{
public partial class Form1 : Form
{
public int index = 0;
public string mirrorPath = "";
public string mirrorWorking = "";
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//创建一个server的本机镜像
//这里首先要去读取一个设定档案查看已经创建的版本库的情况。
// ExecCmd.process_cmd("cd /d D:\\Program Files\\VisualSVN Server\bin");
//ExecCmd.process_cmd("md d:\\mymirror_1");//新增一个根目录
// ExecCmd.process_cmd("svnadmin create d:\\mymirror_1");//创建一个版本目录。
ExecCmd.process_bat("cc");
// ExecCmd.process_bat("xx.bat");
//MessageBox.Show("创建成功!");
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
//
StreamWriter sw = new StreamWriter(@"d:\log.txt",true);
ExecCmd.process_bat1("cc");
sw.WriteLine("this is the "+index.ToString ()+" time executing !");
sw.Close();
index++;
} private void button4_Click(object sender, EventArgs e)
{
//ExecCmd.process_cmd(" ");
folderBrowserDialog1.ShowDialog();
string root = folderBrowserDialog1.SelectedPath;
//digui mydigui = new digui();
//mydigui.finddirectory(root);
digui.finddirectory(root);
ExecCmd.process_bat1("d:\\svndirectory.bat");
MessageBox.Show("已经完成所有的_svn文件的删除!");
//
//现在要做的事情是,得到最新的的镜像版本上的log(比较最近的两个版本),然后从把文件覆盖
compto();
//然后commit到本地的server。
MessageBox.Show("更新成功!!");
}
protected void compto()
{
//选择镜像的版本目录
int verison = 0;
folderBrowserDialog1.ShowDialog();
string root = folderBrowserDialog1.SelectedPath;
folderBrowserDialog1.ShowDialog();
string rootworking = folderBrowserDialog1.SelectedPath;
StreamWriter sw = new StreamWriter(@"c:\svnlog.bat");
string myroot = string.Format("cd /d {0}",root);
sw.WriteLine(myroot);
sw.WriteLine("svn info >>c:\\mylog.txt");
sw.Close();
ExecCmd.process_bat2("c:\\svnlog.bat");
StreamReader sr = new StreamReader(@"c:\mylog.txt");
while (sr.Peek() > 0)
{
string line = sr.ReadLine();
if (line.Contains("Revision:"))
{
string[] cc = line.Split(' ');
verison = Convert.ToInt32(cc[1]);
break;
}
else
{
continue;
}
}
sr.Close();
sw = new StreamWriter(@"c:\svnlog.bat",false);
string myroot1 = string.Format("cd /d {0}", root);
sw.WriteLine(myroot1);
string diffstr = string.Format("svn diff -r {0}:{1} >>c:\\mylog.txt",verison ,verison-1);
sw.WriteLine(diffstr);
sw.Close();
ExecCmd.process_bat2("c:\\svnlog.bat");
sr = new StreamReader(@"c:\mylog.txt");
while (sr.Peek() > 0)
{
string line = sr.ReadLine();
if (line.Contains("Index"))
{
string[] cc = line.Split(':');
//
sw = new StreamWriter(@"c:\svnlog.bat", false);
//把文件copy过去,覆盖,但是还要明确一些delete和一些add的东西
cc[1] = cc[1].Replace('/','\\');
string myroot2 = string.Format("copy {0}\\{1} {2}\\{3}", root,cc[1],rootworking,cc[1]);
sw.WriteLine(myroot2);
sw.Close();
}
else
{
continue;
}
}
sr.Close();
ExecCmd.process_bat2("c:\\svnlog.bat");
string myroute = string.Format("cd /d {0}",rootworking);
ExecCmd.process_cmd2(myroute,"svn update");
} private void comboBox1_Click(object sender, EventArgs e)
{
//选择镜像的存放目录
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorPath = folderBrowserDialog1.SelectedPath;
} private void button2_Click(object sender, EventArgs e)
{
//使镜像和server同步
//首先要做的是修改要获得的目录
ExecCmd.process_bat("cc");
MessageBox.Show("同步完成!");
} private void comboBox2_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorWorking = folderBrowserDialog1.SelectedPath;
} private void button6_Click(object sender, EventArgs e)
{
//使镜像和server同步
//首先要做的是修改要获得的目录
ExecCmd.process_bat("cc");
MessageBox.Show("同步完成!");
} private void button5_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
} private void comboBox3_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorPath = folderBrowserDialog1.SelectedPath;
} private void button7_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 2;
} private void comboBox4_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorWorking = folderBrowserDialog1.SelectedPath;
} private void comboBox5_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorPath = folderBrowserDialog1.SelectedPath;
}
}
}
{
//从镜像获得本地工作目录
//一、从镜像获得本地在server的working
//二、建立一个临时的文件夹存放这个working
//三、删除临时文件夹里面所有的_svn文件夹或者.svn文件夹
//四、把这个文件夹里面的内容copy到实际的工作目录
//五、把这个目录上传到本地的server(此时需要本地server上存放此项目的一个目录)
//六、再从server上checkout下来,覆盖这个文件
//-------这是管理员做的事情
//---------------------------------------------------------------
//从使用者来看,可以先输入一个本的的server,checkout后在操作
StreamWriter sw = new StreamWriter(@"c:\createmirror.bat", false);
sw.WriteLine("echo off");
sw.WriteLine("cd d/ "+textBox3.Text.ToString ());
sw.WriteLine("svn checkout "+textBox3.Text .ToString ()+" "+textBox5.Text .ToString ());
sw.WriteLine("rd c:\\svnmirrorfortemp /s/q");
sw.WriteLine("md c:\\svnmirrorfortemp");
sw.WriteLine("svn checkout +file:///c:/svnmirrorfortemp"+" "+textBox4.Text .ToString ());
} private void button10_Click(object sender, EventArgs e)
{
//创建镜像
StreamWriter sw = new StreamWriter(@"c:\createmirror.bat",false);
sw.WriteLine("echo off");
sw.WriteLine("rd "+mirrorPath+" /s/q");
sw.WriteLine("md"+mirrorPath);
sw.WriteLine("svnadmin create "+ mirrorPath );
sw.WriteLine("copy \\\\172.30.149.69\\down\\meswork\\pre-revprop-change.bat "+mirrorPath+"\\hooks\\");
sw.WriteLine("svnsync init file:///"+mirrorPath +" "+textBox1.Text);
sw.WriteLine("svnsync sync file:///"+mirrorPath);
sw.Close();
ExecCmd.process_bat2(@"c:\createmirror.bat");
MessageBox.Show("创建成功!!");
textBox4.Text = mirrorPath;
tabControl1.SelectedIndex = 2;
} private void textBox3_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorWorking = folderBrowserDialog1.SelectedPath;
} private void textBox4_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = true;
folderBrowserDialog1.ShowDialog();
mirrorPath= folderBrowserDialog1.SelectedPath;
textBox4.Text = mirrorPath;
} private void button8_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
}
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;namespace svnmirror
{
class digui
{
//public int index = 0;
public static void finddirectory(string root)
{
string fathernode = root;
string str1 = string.Format("cd /d {0}",root);
string mydirs = string .Format ("d:\\dir_{0}.txt",DateTime.Now.Millisecond.ToString ());
// index++;
string myreader=string .Format ("dir /a >>{0}",mydirs);
StreamWriter sw2 = new StreamWriter(@"c:\mybat.bat",false);
sw2.WriteLine(str1);
sw2.WriteLine(myreader);
sw2.Close();
ExecCmd.process_bat2(@"c:\mybat.bat");
Thread.Sleep(200);
try
{
StreamReader sr = new StreamReader(mydirs);
while (sr.Peek() > 0)
{
string line = sr.ReadLine();
if (line.Contains("_svn") && line.Contains("DIR"))
{
StreamWriter sw = new StreamWriter(@"d:\svndirectory.bat", true);
sw.WriteLine("rd "+fathernode + "\\_svn"+" /s/q");
sw.Close();
}
else if (line.Contains("DIR") && !line.Contains("."))
{
string[] wholeroute = line.Split(' ');
root = fathernode + "\\" + wholeroute[wholeroute.Length - 1];
finddirectory(root);
}
}
}
catch (Exception ee)
{
//
}
}
}
}