tags:

views:

197

answers:

1

Hi,

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();
            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

A: 

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

Bryce Wagner
Worked a treat, thanks very much!
gondukin