开发者

Issue logging stdout from curl with .net (C#)

开发者 https://www.devze.com 2022-12-21 21:16 出处:网络
I\'m trying to run curl as a process and capture the output from the command window.I have tried both running curl directly as a process and also running cmd and then writing commands to the command p

I'm trying to run curl as a process and capture the output from the command window. I have tried both running curl directly as a process and also running cmd and then writing commands to the command prompt. However, the output from curl itself is not being returned (verbose mode is on), although I sometimes get what looks like an encoding issue, e.g. ÈÆŸ.

If anyone has any inspiration I'd be grateful!

        private static bool ExecuteCurl(string curlDirectory, string curlArgs, string filePath)
        {

            Process process = new Process();
       开发者_C百科     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 [Version 5.1.2600] (C) Copyright 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>exit


Curl seems to send all output to standard error, not standard out.

0

精彩评论

暂无评论...
验证码 换一张
取 消