【发布时间】:2010-03-05 13:22:44
【问题描述】:
我正在尝试将 curl 作为进程运行并捕获命令窗口的输出。我尝试过直接将 curl 作为进程运行,也尝试运行 cmd 然后将命令写入命令提示符。但是,没有返回 curl 本身的输出(详细模式已打开),尽管我有时会遇到编码问题,例如ÈÆŸ。
如果有人有任何启发,我将不胜感激!
private static bool ExecuteCurl(string curlDirectory, string curlArgs, string filePath)
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
StreamWriter sw = process.StandardInput;
StreamReader sr = process.StandardOutput;
sw.WriteLine("cd " + curlDirectory);
sw.WriteLine("curl " + curlArgs + " -F file=@" + filePath);
sw.WriteLine("exit");
sw.Close();
string cURLResults = string.Empty;
cURLResults = sr.ReadToEnd();
sr.Close();
sw = new StreamWriter("C:\\out.txt", true);
sw.WriteLine(cURLResults);
sw.Close();
return false;
}
Microsoft Windows XP [版本 5.1.2600] (C) 版权所有 1985-2001 Microsoft Corp.
C:\Dev\VS\bin>cd C:\cURL\
C:\curl>curl -v -k -u xxxxx:xxxxxxx sftp://ftp.xxxx.co.uk -F file=@C:\mydoc.txt
C:\curl>退出
【问题讨论】: