filehandle

streamReader for server URLs

给你一囗甜甜゛ 提交于 2019-12-10 20:44:39
问题 I've been working with the code form this answer, provided by Martin R. The code is awesome and it is very useful. However, it doesn't work with the links, while working fine with files. After putting some NSLogs and breaks, I have actually found that problem is in this code block: init?(path: String, delimiter: String = "\n", encoding: UInt = NSUTF8StringEncoding, chunkSize : Int = 4096) { self.chunkSize = chunkSize self.encoding = encoding self.fileHandle = NSFileHandle(forReadingFromURL:

Perl Cannot Binmode STDOUT After Untie Filehandle

点点圈 提交于 2019-12-10 15:53:51
问题 I need to disable progressive buffering of an HTTP response. I've got this working in Perl using a file handle class: $|=1; $TIE = tie(*STDOUT,__PACKAGE__); Print statements are stored in an array and are retrieved via the following: $buffer = tied *STDOUT; $buffer = join('', @$buffer); undef $TIE; untie(*STDOUT); If the HTTP response is text/html , it correctly displays in the browser. However, for binary streams, I can't set binmode on STDOUT after it is untied, and the contents are

Program stuck, pipe file descriptor open when shouldn't?

三世轮回 提交于 2019-12-10 14:12:43
问题 I am creating a small shell that can read commands. When I run my program and type: "cat file.txt > file2.txt" it creates the file and then it gets stuck at the line: if(execvp(structVariables->argv[0], argv) < 0). (waiting for input/output??). If I end the program with ctrl + d I can see in my folder that the file is created but nothing has been written in it. (dupPipe is used to handle more commands, not yet used because of problem described above) if((pid = fork()) < 0) { perror("fork

QSerialPort effect on `/dev/ttyS*` after process end?

元气小坏坏 提交于 2019-12-10 13:45:43
问题 When a Qt app using QSerialPort experiences a non-clean shutdown (e.g. due to receiving and not handling SIGINT ), how is the file descriptor of the serial port affected? After running an app that opens a QSerialPort on /dev/ttyS0 , then quitting with Ctl-C , I am finding that cat < /dev/ttyS0 returns instantly (without printing anything) rather than waiting for data (as it usually does). I would expect that if this is due to an open file handle left hanging around, it would show up in the

How to open a file handle on a string in Perl 6?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:35:06
问题 In Perl 5, I can open a filehandle on string like this: open my $kfh, "<", \$message->payload; I have a scenario that uses string as a filehandle and passes it to the open method: my $fh = new IO::Zlib; open my $kfh, "<", \$message->payload; if($fh->open($kfh, 'rb')){ print <$fh>; $fh->close; } where $message->payload is read from Kafka, and the content is a byte array. raiph had a similar question, but it didn't answer my question. So I want to know how to open a filehandle on a string in

How to release a handle through C#?

我是研究僧i 提交于 2019-12-09 07:34:27
I have an application that IMPLICITLY opens a handle on a dll/file. At some point in the application, I want to release this handle. How can I do it? My application is in C#. use PInvoke if you have an handler that you want to close [System.Runtime.InteropServices.DllImport("Kernel32")] private extern static Boolean CloseHandle(IntPtr handle); What exactly you are trying to do? If you want to load an assembly to do some stuff with that, and then unload it completely, you need to rely on creating a new app domain. public static void Main(string[] args) { AppDomain appDomain = AppDomain

How can I check if a filehandle is open in Perl? [duplicate]

寵の児 提交于 2019-12-09 00:27:59
问题 This question already has answers here : How can I test if I can write to a filehandle? (5 answers) Closed 2 years ago . Is there a way to check if a file is already open in Perl? I want to have a read file access, so don't require flock . open(FH, "<$fileName") or die "$!\n" if (<FILE_IS_NOT_ALREADY_OPEN>); # or something like close(FH) if (<FILE_IS_OPEN>); 回答1: Please see the answer regarding openhandle() from Scalar::Util. The answer I originally wrote here was once the best we could do,

How can I store and access a filehandle in a Perl class?

≯℡__Kan透↙ 提交于 2019-12-08 20:09:47
问题 please look at the following code first. #! /usr/bin/perl package foo; sub new { my $pkg = shift; my $self = {}; my $self->{_fd} = undef; bless $self, $pkg; return $self; } sub Setfd { my $self = shift; my $fd = shift; $self_->{_fd} = $fd; } sub write { my $self = shift; print $self->{_fd} "hello word"; } my $foo = new foo; My intention is to store a file handle within a class using hash. the file handle is undefined at first, but can be initilized afterwards by calling Setfd function. then

Read file into variable in Perl [duplicate]

a 夏天 提交于 2019-12-08 14:54:26
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What is the best way to slurp a file into a string in Perl? Is this code a good way to read the contents of a file into a variable in Perl? It works, but I'm curious if there is a better practice I should be using. open INPUT, "input.txt"; undef $/; $content = <INPUT>; close INPUT; $/ = "\n"; 回答1: I think common practice is something like this: my $content; open(my $fh, '<', $filename) or die "cannot open file

How to release a handle through C#?

只谈情不闲聊 提交于 2019-12-08 05:23:02
问题 I have an application that IMPLICITLY opens a handle on a dll/file. At some point in the application, I want to release this handle. How can I do it? My application is in C#. 回答1: use PInvoke if you have an handler that you want to close [System.Runtime.InteropServices.DllImport("Kernel32")] private extern static Boolean CloseHandle(IntPtr handle); 回答2: What exactly you are trying to do? If you want to load an assembly to do some stuff with that, and then unload it completely, you need to