streamwriter

CsvHelper wrap all valus with quotes

假装没事ソ 提交于 2020-07-03 03:20:10
问题 I am using CsvHelper I need to wrap all values with quotes. Is that possible? Data = is a List using (StreamWriter textWriter = new StreamWriter(path)) { textWriter.BaseStream.Write(p, 0, p.Length); // var dt = new DataTable(); var csv = new CsvWriter(textWriter); csv.WriteRecords(Data); textWriter.Flush(); textWriter.Close(); } Thanks 回答1: There is a config value called ShouldQuote where you can determine on a field level if it should be quoted. void Main() { var records = new List<Foo> {

Shortest way to save DataTable to Textfile

无人久伴 提交于 2020-04-10 08:23:06
问题 I just found a few answers for this, but found them all horribly long with lots of iterations, so I came up with my own solution: Convert table to string: string myTableAsString = String.Join(Environment.NewLine, myDataTable.Rows.Cast<DataRow>(). Select(r => r.ItemArray).ToArray(). Select(x => String.Join("\t", x.Cast<string>()))); Then simply save string to text file, for example: StreamWriter myFile = new StreamWriter("fileName.txt"); myFile.WriteLine(myFile); myFile.Close(); Is there a

Why should asyncio.StreamWriter.drain be explicitly called?

放肆的年华 提交于 2020-02-18 05:30:22
问题 From doc: https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.write write(data) Write data to the stream. This method is not subject to flow control. Calls to write() should be followed by drain(). coroutine drain() Wait until it is appropriate to resume writing to the stream. Example: writer.write(data) await writer.drain() From what I understand, You need to call drain every time write is called. If not I guess, write will block the loop thread Then why is write not a

Why should asyncio.StreamWriter.drain be explicitly called?

安稳与你 提交于 2020-02-18 05:29:28
问题 From doc: https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.write write(data) Write data to the stream. This method is not subject to flow control. Calls to write() should be followed by drain(). coroutine drain() Wait until it is appropriate to resume writing to the stream. Example: writer.write(data) await writer.drain() From what I understand, You need to call drain every time write is called. If not I guess, write will block the loop thread Then why is write not a

Reading from the Pipeline Stream in PowerShell

早过忘川 提交于 2020-01-25 23:46:51
问题 Background I'm hoping to write code which uses Microsoft.VisualBasic.FileIO.TextFieldParser to parse some csv data. The system I'm generating this data for doesn't understand quotes; so I can't escape the delimiter; but rather have to replace it. I've found a solution using the above text parser, but I've only seen people use it with input from files. Rather than writing my data to file only to import it again, I'd rather keep things in memory / make use of this class's constructor which

Reading from the Pipeline Stream in PowerShell

前提是你 提交于 2020-01-25 23:46:13
问题 Background I'm hoping to write code which uses Microsoft.VisualBasic.FileIO.TextFieldParser to parse some csv data. The system I'm generating this data for doesn't understand quotes; so I can't escape the delimiter; but rather have to replace it. I've found a solution using the above text parser, but I've only seen people use it with input from files. Rather than writing my data to file only to import it again, I'd rather keep things in memory / make use of this class's constructor which

How to run multiple lines in cmd as administrator using C#?

大城市里の小女人 提交于 2020-01-25 13:12:08
问题 Is there a work around or a function that lets me run multiple commands in one elevated command prompt? I tried setting UseShellExecute=false and use StreamWriter, but I read that if I do that, I can't use an elevated command prompt. If I set UseShellExecute=true, I can use the elevate cmd but I need to use process.Argument() which only lets me run one command in one cmd process at a time. I have a loop that runs one command at a time in different cmd process and it works. But it just gets

How to send keys instead of characters to a process?

自闭症网瘾萝莉.ら 提交于 2020-01-19 03:21:46
问题 System.Diagnostics.Process exposes a StreamWriter named StandardInput, which accepts only characters as far as I know. But I need to send keystrokes as well, and some keystrokes don't map well to characters. What should I do? 回答1: You are mixing input streams with control signals. A console process has a default input stream which you can control with the StandardInput, as you already know. But Ctrl-C and Ctrl-Break are not characters sent to the process through this stream, but instead they

How can I feed commands to cmd.exe process via an input stream manually?

心不动则不痛 提交于 2020-01-11 14:45:13
问题 The question sounds a bit, dense. Here is a slightly longer version: I need to have the main loop wait for user input and also have a process running and waiting for input from a stream to which the user input is to be sent. Full story: I'm building a Cmd emulator and at first everything looked fine: The user enters a command, it gets echoed to the output area, processed and StdOut and StdErrOut are captured and also added to the output TextBox. The only problem was, that, as the cmd process

StreamWriter automatically flushing buffer when given large messages

一个人想着一个人 提交于 2020-01-11 10:23:50
问题 Overview I have a Client-Server whereby I have the streamWriter.WriteLine(messageToClient); on the server sending large messages. The streamReader.ReadLine(); on the client is reading the 2000 length messages fine. The issue here is the streamWriter.Flush() has no affect on the larger messages, because what I am aiming for is the server to be able to switch between the buffers flushing directly (having a fluid server message output) and not (the server response would be jumbled together until