使用 .net (C#) 从curl 记录标准输出时出现问题
我正在尝试将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>退出
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Curl 似乎将所有输出发送到标准错误,而不是标准输出。
Curl seems to send all output to standard error, not standard out.