私は中国出身ですから、英語が苦手なのかもしれません。私はあなたが私の質問を理解できるように最善を尽くしています。 C#プロジェクトでPHP CLIを使いたいです。 私が返された文字列として、このC#でPHP CLIを使うには
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
try
{
p.Start();
p.StandardInput.WriteLine(command);
p.StandardInput.WriteLine("exit");
p.WaitForExit(1000);
StreamReader reader = new StreamReader(p.StandardOutput.BaseStream, Encoding.GetEncoding("utf-8"));
string text= reader.ReadToEnd();
if (text.IndexOf(command) != -1)
{
int start = text.IndexOf(command) + command.Length;
string endstring = rootpath + ">exit";
int end = text.IndexOf(endstring);
text = text.Substring(start, text.Length - start - endstring.Length).Trim();
return text;
}
return "";
}
catch (System.Exception ex)
{
return "";
}
finally
{
p.Close();
}
のようなコードを試してみましたが、私は正しい結果を得るために、部分文字列を使用しますが、時々私は私が真実でに欲しいものを得ることができない、私は必要なものではありません。 私の方法は正しいとは思わないかもしれませんが、私はインターネットからの情報を見つけることができません。
私を助けることができますか?どうもありがとうございました!あなたの返信をお待ちしております。
質問を書式設定し、コードタグでコードを囲みます。 – Roman
実際の結果がどのようなものか、予想される結果がどのようなものか説明してください。 – Oded