首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对发送到命令的c#命令使用引号

对发送到命令的c#命令使用引号
EN

Stack Overflow用户
提问于 2018-11-04 17:35:45
回答 1查看 94关注 0票数 0

我已经搜索了很多关于这方面的信息,但没有任何针对这种特定情况的示例。

我想压缩写在文本框(dirdes)上的目录,并在富文本框(_output)上显示输出。

它不是压缩写在文本框上的目录,而是压缩bin目录。

代码语言:javascript
复制
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:\'

EN

回答 1

Stack Overflow用户

发布于 2018-11-04 19:51:14

我在GUI中混合了文本框名称...这花了我24小时!我稍微修改了一下代码。现在它开始工作了

代码语言:javascript
复制
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;

    }

有些变量是用来测试的,不用担心

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53139410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档