Questions tagged [filehandle]

A file handle is an abstract indicator for accessing a file. It is retrieved after successfully opening the file using the file name. Afterwards the file handle is used instead of the file name for all file operations.

407 questions
15
votes
2 answers

Is there are Python equivalent of Perl's __DATA__ filehandle?

In Perl I often read data in from the filehandle __DATA__ at the end of the script: while () { chomp; say; } __DATA__ line1 line2 I find this quicker for testing code etc than reading in a file, as it means I can edit its contents on…
fugu
  • 6,417
  • 5
  • 40
  • 75
14
votes
3 answers

Delphi - finding the process that is accessing a file from my program

I have a Delphi app that regularly writes to a local disk file. Occasionally it is unable to access the file - a sharing violation results when it tries to open it. A retry after a short delay is all that is needed, but when it occurs, I would…
rossmcm
  • 5,493
  • 10
  • 55
  • 118
14
votes
1 answer

How do I determine whether a Perl file handle is a read or write handle?

You are given either an IO::File object or a typeglob (\*STDOUT or Symbol::symbol_to_ref("main::FH")); how would you go about determining if it is a read or write handle? The interface cannot be extended to pass this information (I am overriding…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
14
votes
1 answer

I can create filehandles to strings in Perl 5, how do I do it in Perl 6?

In Perl 5, I can create a filehandle to a string and read or write from the string as if it were a file. This is great for working with tests or templates. For example: use v5.10; use strict; use warnings; my $text = "A\nB\nC\n"; open(my $fh, '<',…
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
14
votes
2 answers

Prevent strings from being interpreted as a file handle

Perl has the feature that strings named like a file handle are taken to be a filehandle: # let this be some nice class I wrote package Input { sub awesome { ... } } So when we do Input->awesome or extra-careful: 'Input'->awesome, the method…
amon
  • 57,091
  • 2
  • 89
  • 149
13
votes
5 answers

How can I test if I can write to a filehandle?

I have some subroutines that I call like this myWrite($fileName, \@data). myWrite() opens the file and writes out the data in some way. I want to modify myWrite so that I can call it as above or with a filehandle as the first argument. (The main…
flies
  • 2,017
  • 2
  • 24
  • 37
12
votes
2 answers

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

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…
Brad Wood
  • 3,863
  • 16
  • 23
12
votes
5 answers

Is there a way to access a string as a filehandle in php?

I'm on a server where I'm limited to PHP 5.2.6 which means str_getcsv is not available to me. I'm using, instead fgetcsv which requires "A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen()." to operate on. My…
Erik
  • 20,526
  • 8
  • 45
  • 76
11
votes
5 answers

Python equivalent of piping file output to gzip in Perl using a pipe

I need to figure out how to write file output to a compressed file in Python, similar to the two-liner below: open ZIPPED, "| gzip -c > zipped.gz"; print ZIPPED "Hello world\n"; In Perl, this uses Unix gzip to compress whatever you print to the…
bu11d0zer
  • 433
  • 4
  • 13
11
votes
5 answers

Why does Programming Perl use local (not my) for filehandles?

When I read through Programming Perl, 2nd Edition, Page 51, something confuses me : sub newopen { my $path = shift; local *FH; #not my! open (FH, $path) || return undef; return *FH; } $fh = newopen('/etc/passwd'); My I know, why…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
10
votes
4 answers

What is the difference between writing to STDOUT and a filehandle opened to "/dev/tty"?

What are the differences between this two examples? #!/usr/bin/perl use warnings; use 5.012; my $str = "\x{263a}"; open my $tty, '>:encoding(utf8)', '/dev/tty' or die $!; say $tty $str; close $tty; open $tty, '>:bytes', '/dev/tty' or die $!; say…
sid_com
  • 24,137
  • 26
  • 96
  • 187
10
votes
4 answers

Sending data to a program via stdin and ostream. (C++)

I would like to send data from within my C++ program to an external pipeline, like so: FILE* file = popen("my_prog -opt | other_prog", "w"); std::ostream fileStream = some_function(file); fileStream << "some data"; I understand there is no simple,…
Drew
  • 12,578
  • 11
  • 58
  • 98
9
votes
3 answers

Can I use Text::CSV_XS to parse a csv-format string without writing it to disk?

I am getting a "csv file" from a vendor (using their API), but what they do is just spew the whole thing into their response. It wouldn't be a significant problem except that, of course, some of those pesky humans entered the data and put in…
Paul R N
  • 93
  • 3
9
votes
2 answers

Why does Perl open() documentation use two different FILEHANDLE styles?

The documentation for the open function shows the syntax of open() as: open FILEHANDLE,EXPR open FILEHANDLE,MODE,EXPR open FILEHANDLE,MODE,EXPR,LIST open FILEHANDLE,MODE,REFERENCE open FILEHANDLE Down in the examples they have places where a…
Scooter
  • 6,802
  • 8
  • 41
  • 64
8
votes
3 answers

Open filehandle or assign stdout

I'm working in a program where the user can pass a -o file option, and output should be then directed to that file. Otherwise, it should go to stdout. To retrieve the option I'm using the module getopt long, and that's not the problem. The problem…
cmre
  • 83
  • 1
  • 3
1
2
3
27 28