filehandle

Where does Ruby keep track of its open file descriptors?

五迷三道 提交于 2019-12-03 02:32:27
What This Question Is Not About This question is not about how to auto-close a file with File#close or the File#open block syntax. It's a question about where Ruby stores its list of open file descriptors at runtime. The Actual Question If you have a program with open descriptors, but you don't have access to the related File or IO object, how can you find a reference to the currently-open file descriptors? Take this example: filename='/tmp/foo' %x( touch "#{filename}" ) File.open(filename) filehandle = File.open(filename) The first File instance is opened, but the reference to the object is

Open in Java(TM) Platform SE binary

耗尽温柔 提交于 2019-12-02 23:27:49
I tried to delete a file that I have two of, one slightly changed, so I could delete the older one and replace it with the new one I changed. When I tried to delete the file I got the error message 'file in use' where it said the action can't be completed because the file is open in Java(TM) Platform SE binary. How do I close it? robguinness This is what worked for me (using Windows). It is basically the same procedure as commented by ali haider, but with more details... Using Windows command prompt: tasklist | findstr java ("findstr" is a command line utility for Windows similar to "grep" in

Perl - while (<>) file handling [duplicate]

大憨熊 提交于 2019-12-02 20:38:25
This question already has an answer here : Which file is Perl's diamond operator (null file handle) currently reading from? (1 answer) A simple program with while( <> ) handles files given as arguments ( ./program 1.file 2.file 3.file ) and standard input of Unix systems. I think it concatenates them together in one file and work is line by line. The problem is, how do I know that I'm working with the first file? And then with the second one. For a simple example, I want to print the file's content in one line. while( <> ){ print "\n" if (it's the second file already); print $_; } The diamond

confusing filehandle in perl

╄→гoц情女王★ 提交于 2019-12-02 08:58:18
Have been playing with the following script but still couldn't understand the meaning behind the two different "kinds" of filehandle forms. Any insight will be hugely appreciated. #! usr/bin/perl use warnings; use strict; open (FH, "example.txt") or die $!; while (<FH>) { my @line = split (/\t/, $_); { print "@line","\n"; } } The output is as expected: @line array contains elements from line 1,2,3 ... from example.txt . As I was told that open (FH, example.txt) is not as good as open (my $fh, '<', 'example.txt') , I changed it but then confusion arose. From what I found, $fh is scalar and

Usage of defined with Filehandle and while Loop

自闭症网瘾萝莉.ら 提交于 2019-12-02 00:12:51
问题 While reading a book on advanced Perl programming (1) , I came across this code: while (defined($s = <>)) { ... Is there any special reason for using defined here? The documentation for perlop says: In these loop constructs, the assigned value (whether assignment is automatic or explicit) is then tested to see whether it is defined. The defined test avoids problems where line has a string value that would be treated as false by Perl, for example a "" or a "0" with no trailing newline. If you

Usage of defined with Filehandle and while Loop

依然范特西╮ 提交于 2019-12-01 21:33:38
While reading a book on advanced Perl programming (1) , I came across this code: while (defined($s = <>)) { ... Is there any special reason for using defined here? The documentation for perlop says: In these loop constructs, the assigned value (whether assignment is automatic or explicit) is then tested to see whether it is defined. The defined test avoids problems where line has a string value that would be treated as false by Perl, for example a "" or a "0" with no trailing newline. If you really mean for such values to terminate the loop, they should be tested for explicitly: [...] So,

When does ref($variable) return 'IO'?

断了今生、忘了曾经 提交于 2019-12-01 19:04:06
Here's the relevant excerpt from the documentation of the ref function: The value returned depends on the type of thing the reference is a reference to. Builtin types include: SCALAR ARRAY HASH CODE REF GLOB LVALUE FORMAT IO VSTRING Regexp Based on this, I imagined that calling ref on a filehandle would return 'IO' . Surprisingly, it doesn't: use strict; use warnings; open my $fileHandle, '<', 'aValidFile'; close $fileHandle; print ref $fileHandle; # prints 'GLOB', not 'IO' perlref tries to explain why: It isn't possible to create a true reference to an IO handle (filehandle or dirhandle)

How do I release file system locks after cloning repo via JGit

人盡茶涼 提交于 2019-12-01 16:05:09
I am playing around with cloning a remote existing repo with jGit following the guide here: https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java I'm using CFML for my example: Git = createObject( 'java', 'org.eclipse.jgit.api.Git' ); localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) ); result = Git.cloneRepository() .setURI( 'https://github.com/github/testrepo.git' ) .setDirectory( localPath ) .call(); result.close(); The clone works great, but file locks are not released on "pack" files inside

How do I release file system locks after cloning repo via JGit

情到浓时终转凉″ 提交于 2019-12-01 15:05:36
问题 I am playing around with cloning a remote existing repo with jGit following the guide here: https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java I'm using CFML for my example: Git = createObject( 'java', 'org.eclipse.jgit.api.Git' ); localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) ); result = Git.cloneRepository() .setURI( 'https://github.com/github/testrepo.git' ) .setDirectory( localPath )

Pass file handle to cython function

旧时模样 提交于 2019-12-01 06:42:23
I want to compile a python function with cython, for reading a binary file skipping some records (without reading the whole file and then slicing, as I would run out of memory). I can come up with something like this: def FromFileSkip(fid, count=1, skip=0): if skip>=0: data = numpy.zeros(count) k = 0 while k<count: try: data[k] = numpy.fromfile(fid, count=1, dtype=dtype) fid.seek(skip, 1) k +=1 except ValueError: data = data[:k] break return data and then I can use the function like this: f = open(filename) data = FromFileSkip(f,... However, for compiling the function "FromFileSkip" with