【问题标题】:Issue logging stdout from curl with .net (C#)使用 .net (C#) 从 curl 记录标准输出
【发布时间】: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>退出

【问题讨论】:

    标签: c# process curl


    【解决方案1】:

    Curl 似乎将所有输出发送到标准错误,而不是标准输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 1970-01-01
      • 2015-07-15
      • 2016-09-24
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多