多行不显示和cmd命令无法执行

时间:2015-08-09 06:54:22

标签: c# winforms

我现在已经连续几个小时试图解决这个问题,但我不能。我正在开发一个为MaxCSO制作GUI的项目。到目前为止,我已经成功,但现在我被卡住了。 首先,我无法在输入框中使用多行+滚动条(滚动条不起作用,文本框仅显示列表中选择的最后一个文件) (已修复) ,其次我无法获取执行命令提示符(几乎已修复但现在我需要一种方法可以保存 openFileDialog中的文件[如另存为窗口]) (已修复)并选择多个文件会导致MaxCSO抛出错误输出太少(我相信它可以通过在每个输出字符串之前添加-o来修复,但我不知道如何让它做到这一点。

这是我的代码:

namespace MaxCSO
{
    public partial class MaxCSOGUI : Form
    {
        //Used to update the text box to the selected input file from openFileDialog
        public string ISOinputFolder
        {
            get { return ISOin.Text; }
            set { ISOin.Text = value; }
        }

        //Used to update the output text box to the selected output dest. in openFileDialog
        string CSOoutputFolder;

        private void OutBrowse_Click(object sender, EventArgs e)
        {
            //User selected output path
            SaveFileDialog Output = new SaveFileDialog();
            //Output.Multiselect = true;
            Output.Title = "Set location to save the CSO/s...";
            Output.Filter = "Compressed Disk Image Files(.cso)|*.cso";
            DialogResult dr = Output.ShowDialog();
            //Sets the default output folder to the same as the input if no output is selected
            if (dr == DialogResult.OK || dr == DialogResult.Yes) {
                CSOoutputFolder = Output.FileNames + "\\";
            }else{
                CSOoutputFolder = ISOinputFolder;
            }
                CSOout.Text = CSOoutputFolder;
        }
        //Input Browse button
        private void InBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog Input = new OpenFileDialog();
            Input.Multiselect = true;
            Input.Title = "Select ISO/s to convert...";
            Input.Filter = "Disk Image Files(.iso)|*.iso";
            DialogResult dr = Input.ShowDialog();

            if (dr == DialogResult.OK || dr == DialogResult.Yes)

                //Outputs all selected .iso files to convert
                ISOin.Text = string.Format("{0}", string.Join(" ", Input.FileNames));
        }

        //Confirm button
        private void Confirm_Click(object sender, EventArgs e)
        {
            //Makes sure neither text box is empty before the program continues(program still tries to launch so this isn't working)
            if ((ISOin != null) && (CSOout != null)) {
                compressISO();
            }
        }

        //Cancel Button
        public void Cancel_Click(object sender, EventArgs e)
        {
            //Used to show cancel confirmation box
            ConfirmClose frm2 = new ConfirmClose();
            frm2.ShowDialog();
        }


        //Supposed to launch a CMD that executes a command that begins compressing the selected iso files
        private void compressISO()
        {
            string Compress;
            Compress = "/K maxcso64.exe --use-zopfli " + ISOin.Text + " " + "-o " + CSOout.Text + ".cso";
            Process.Start("CMD.exe", Compress);
        }
    }
}

P.S。我只是复制粘贴整个文件,万一我错过了一些错误的东西,可以指出,因为我是一个总菜鸟)

更新:有没有办法在执行命令之前将cmd设置为打开到特定路径(例如C:\ Program Files),是否有办法设置-o之前输出文本框中的每一行(例如 -o C:\ Users \ Jack \ Desktop \ File1.cso -o C:\ Users \ Jack \ Desktop \ File2.cso

1 个答案:

答案 0 :(得分:0)

查看您的代码我可以看到很多问题,但您现在遇到的问题是cmd.exe缺少参数以保持控制台窗口打开。

只需将命令行更改为

即可
private void compressISO() 
{
     string Compress;
     Compress = "/K maxcso.exe --use-zopfli " + ISOin.Text + " " + "-o " + CSOout.Text + ".cso";
     Process.Start("CMD.exe", Compress);
}

那么可能你会得到其他错误,但至少你可以看到它们并报告它们。修复错误后,如果您不希望在/K程序终止其工作后保持控制台窗口打开,则可以将/C更改为maxcso

See CMD.EXE Command Shell