0

開始時にSourcePathを要求するコンソール アプリケーションがあります。ソース パスを入力すると、DestinationPathが要求されます。

私の問題は、Windowsアプリケーションを介してこれらのパスを提供することです。つまり、特定の時間間隔後にこれらのパラメーターをコンソールアプリケーションに自動的に提供するウィンドウフォームアプリケーションを作成する必要があります

達成できるかどうか...もしそうなら、助けてください...非常に緊急です...

ああ..貼り付けることができない多くのコードを試しましたが、アプリケーションの起動に使用するものは...

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe";
        psi.UseShellExecute = false;
        psi.RedirectStandardError = true;
        psi.RedirectStandardInput = true;
        psi.CreateNoWindow = false;
            psi.Arguments = input + ";" + output;
        Process p = Process.Start(psi);

        Process process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                CreateNoWindow = true,
                FileName = @"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe",
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
            }
        };
        if (process.Start())
        {
            Redirect(process.StandardError, text);
            Redirect(process.StandardOutput, text);
            MessageBox.Show(text);
        }
    private void Redirect(StreamReader input, string output)
    {
        new Thread(a =>{var buffer = new char[1];
            while (input.Read(buffer, 0, 1) > 0)
            {
                output += new string(buffer);
            };
        }).Start();
    }

しかし、何も機能していないようです

4

1 に答える 1

0

次のように ProcessStartInfo にパラメーターを追加できます。

 ProcessStartInfo psi = new ProcessStartInfo(@"C:\MyConsoleApp.exe",
     @"C:\MyLocationAsFirstParamter C:\MyOtherLocationAsSecondParameter");
 Process p = Process.Start(psi);

これにより、2 つのパラメーターを使用してコンソール アプリが起動されます。これで、コンソール アプリに

 static void Main(string[] args)

文字列配列 args はパラメーターを含むものであり、あとはアプリの起動時にパラメーターを取得するだけです。

if (args == null || args.Length < 2)
{
    //the arguments are not passed correctly, or not at all
}
else
{
    try
    {
        yourFirstVariable = args[0];
        yourSecondVariable = args[1];
    }
    catch(Exception e)
    {
        Console.WriteLine("Something went wrong with setting the variables.")
        Console.WriteLine(e.Message);
    }
}

これは、必要なコードである場合とそうでない場合がありますが、少なくとも、目的を達成する方法についての洞察が得られます。

于 2013-01-10T10:36:19.043 に答える