我有一个批处理文件,它基本上从站点下载文件或返回错误消息,说文件不可用.我想在C#(SSIS脚本组件)中执行此.bat文件并将文件名保存到变量(如果文件已下载)或将错误消息分配给变量.
先感谢您
dri*_*iis 10
使用Process.Start执行批处理文件.您可以通过在返回的Process对象上读取StandardError和StandardOutput流来将过程输出作为文本获取.您需要将该RedirectStandardOutput属性设置为true.
以下是MSDN的一个示例:
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "yourbatchfile.bat";
p.Start();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3346 次 |
| 最近记录: |