如何将批处理文件的输出记录到C#中的表中? [英] How to log output from a batch file to a table in C#?

查看:89
本文介绍了如何将批处理文件的输出记录到C#中的表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ProcessStartInfo类从C#代码运行批处理文件,并希望通过调用存储过程将其输出记录到表中。

我能够从代码中执行批处理文件,但无法记录其输出。

任何人都可以帮我这个功能吗?

解决方案

首先,捕获输出 - < a href =https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput(v=vs.110).aspx> MSDN [ ^ ]向您展示了如何做到这一点。



然后由您决定:如果您只想将整个输出作为列,只需通过参数化INSERT将字符串传递给SQL查询。

如果你需要将它分成几行,一列或两者,那么你需要仔细查看输出数据 - 没有适合每种数据格式的建议! / BLOCKQUOTE>

I am trying to run a batch file from C# code using ProcessStartInfo class and want to log its output to the table by calling a Stored Proc.
I am able to execute batch file from the code, but not able to log its output.
Can anyone please help me with this functionality?

解决方案

First, capture the output - MSDN[^] shows you how to do that.

Then it's up to you: if you just want the whole output as a column, just pass the string to SQL via a Parameterized INSERT query.
If you need to break it into several rows, or columns, or both then you need to look closely at the output data - there is no advice which will fit every data format!


这篇关于如何将批处理文件的输出记录到C#中的表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆