来自 Web 服务 ASP.NET C# 的 Cygwin 命令
我想从 Web 服务中执行 cygwin 命令。
基本上我想使用“tail”命令来删除 C# 中文件的第一行。
I want to execute a cygwin command from within a webservice.
Basically I want to use the "tail" command to strip off the first line of a file in C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
调用另一个程序只是为了删除文件的第一行听起来是一个非常糟糕的主意。您可能想尝试只删除 C# 中的第一行。
Calling another program just to strip the first line of a file sounds like a very bad idea. You might want to try and just strip the first line in C#.
我以前没有亲自处理过巨大的文本文件,所以我做了一些搜索;
从文本文件中删除行的有效方法
基本上,这个给出了您不喜欢的答案,但如果 .NET 4 是一个选项,那么内存映射文件可能会帮助您。
I've not personally dealt with huge text files before, so I did a bit of searching around;
Efficient way to delete a line from a text file
Basically, this one gives an answer you don't like, but if .NET 4 is an option memory-mapped files might help you out.
您想删除它还是阅读它?如果你想要文件的第一行,你可以打开文件流(File.Open)并获取第一行。
Are you looking to remove it or read it? If you want the first line of the file, you can just open the file stream (File.Open) and take the first line.
通常,Cygwin 安装在 C:\CYGWIN 中,因此您应该能够通过从代码中调用“C:\cygwin\usr\bin\tail.exe”来运行 tail(从 /usr/bin)。
也就是说,你根本不应该这样做。只需正确使用 StreamReader 即可。这个问题有一个很好的例子来展示如何: 使用流读取大型文本文件在 C# 中
Normally Cygwin is installed in C:\CYGWIN so you should be able to run tail (from /usr/bin) by calling "C:\cygwin\usr\bin\tail.exe" from your code.
That said, you really should not be doing this at all. Just use a StreamReader properly. This question has a nice example to show how: Reading large text files with streams in C#