我已经搜索了很多关于这方面的信息,但没有任何针对这种特定情况的示例。
我想压缩写在文本框(dirdes)上的目录,并在富文本框(_output)上显示输出。
它不是压缩写在文本框上的目录,而是压缩bin目录。
private void button3_Click(object sender, EventArgs e)
{
string dirdes1 = dirdes.Text;
string strCmdText;
strCmdText = "/C compact /c /s /a /i /exe:lzx '" + dirdes1 + " *'";
Process lzx = new Process();
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
lzx.StartInfo.FileName = "cmd.exe";
lzx.StartInfo.UseShellExecute = false;
lzx.StartInfo.Arguments = strCmdText;
lzx.StartInfo.RedirectStandardOutput = true;
lzx.Start();
_output.Text = lzx.StandardOutput.ReadToEnd();
}编辑:我认为这是一个引用错误。因为目录必须像这样的"C:\",而不像这样的'C:\'
发布于 2018-11-04 19:51:14
我在GUI中混合了文本框名称...这花了我24小时!我稍微修改了一下代码。现在它开始工作了
private void button3_Click(object sender, EventArgs e)
{
string dirdes1 = dirdes.Text;
string strCmdText;
string locationAddress;
string cdCommand;
string doCompress;
locationAddress = dirdes1;
cdCommand = "/C " + "cd " + locationAddress;
strCmdText = "compact /c /s /a /i /exe:lzx";
doCompress = "/C " + strCmdText + " *";
Process lzx = new Process();
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
lzx.StartInfo.FileName = "cmd.exe";
lzx.StartInfo.UseShellExecute = false;
lzx.StartInfo.WorkingDirectory = @locationAddress;
lzx.StartInfo.Arguments = doCompress;
lzx.StartInfo.RedirectStandardOutput = true;
lzx.Start();
_output.Text = lzx.StandardOutput.ReadToEnd();
showCommand.Text = doCompress;
}有些变量是用来测试的,不用担心
https://stackoverflow.com/questions/53139410
复制相似问题