-2

ここでの以前の質問から、CMD を介して多数のファイルを実行するプログラムを作成していました。

これが私のコードです

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;

namespace Convert
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

    private void BtnSelect_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog Open = new OpenFileDialog();
        Open.Filter = "RIFF/RIFX (*.Wav)|*.wav";
        Open.CheckFileExists = true;
        Open.Multiselect = true;
        Open.ShowDialog();
        LstFile.Items.Clear();
        foreach (string file in Open.FileNames)
        {
            LstFile.Items.Add(file);
        }
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        LstFile.Items.Clear();
    }

    private void BtnConvert_Click(object sender, RoutedEventArgs e)
    {       Process p = new Process();      
            p.StartInfo.FileName = "cmd";
            p.StartInfo.UseShellExecute = false;
            foreach (string fn in LstFile.Items)
            {
                string fil = "\"";
                string gn = fil + fn + fil;
                p.Start();
                p.StartInfo.Arguments = gn;
            }            
        }      
    }    
}

私が使った

string fil = "\"";
string gn = fil + fn + fil;

ファイル名にスペースが含まれている場合に備えて、完全なファイル名を引用符で囲みます。

私の問題は、私のプログラム Opens CMD Put が引数を渡さないことです.filnames(リスト)が機能しているかどうかを確認しましたが、それらは問題ありません.例を見ると、これはそれを行う方法ですが、明らかに何かが間違っています.

4

1 に答える 1

2

設定

StartInfo.Arguements 

プロセスを開始する前に、開始するプロセスごとに新しいプロセス クラスを作成することをお勧めします。

例:

        foreach (string fn in LstFile.Items)
        {
            string fil = "\"";
            string gn = fil + fn + fil;

            Process p = new Process();
            p.StartInfo.FileName = "cmd";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.Arguments = gn;
            //You can do other stuff with p.StartInfo such as redirecting the output
            p.Start();
            // i'd suggest adding p to a list or calling p.WaitForExit();, 
            //depending on your needs.  
        }

cmd コマンドを呼び出そうとしている場合は、自分の意見を述べてください

"/c \"what i would type into the command Line\""

これは私が素早くやった例です。メモ帳でテキスト ドキュメントを開きます

        Process p = new Process();
        p.StartInfo.FileName = "cmd";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.Arguments = "/c \"New Text Document.txt\"";
        p.Start();
        p.WaitForExit();
于 2012-07-17T14:50:18.970 に答える