filehandle

How can I use tie() to redirect STDOUT, STDERR only for certain packages?

自作多情 提交于 2019-12-08 03:02:07
问题 I need to work with some libraries that unfortunately log diagnostic messages to STDOUT and STDERR. By using tie , I can redirect those writes to a function that captures those. Since I don't want all STDOUT and STDERR output of my programs to be captured thtough the tied handle, I'd like to do this only for certain packages. I have come up with a solution where the actual behavior is determined by looking at caller() as can be seen below, but I have the feeling that there has to be a better

List all currently open file handles? [duplicate]

跟風遠走 提交于 2019-12-07 04:41:20
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: check what files are open in Python Hello, Is it possible to obtain a list of all currently open file handles, I presume that they are stored somewhere in the environment. I am interested in theis function as I would like to safely handle any files that are open when a fatal error is raised, i.e. close file handles and replace potentially corrupted files with the original files. I have the handling working but

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

半腔热情 提交于 2019-12-06 23:19:55
问题 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 normal $-prefixed variable is used for the file handle: open(my $fh, "<", "input.txt") and also examples where a bareword is used: open(FOO, "|tr '[a-z]' '[A-Z]'"); One question is what is the name of each style as in "I am using _ _ for a filehandle" in

perl share filehandle with threads

时光总嘲笑我的痴心妄想 提交于 2019-12-06 16:26:06
问题 I've found the code below online, it seems the way the program control the loop is to check the shared variable $TERM is 0 or not. Can I share a filehandle between threads, that every thread deal with one line of a file and loop ends when the file reaches the last line? #!/usr/bin/perl use strict; use warnings; use threads 1.39; use threads::shared; use Thread::Queue; ### Global Variables ### # Maximum working threads my $MAX_THREADS = 10; # Flag to inform all threads that application is

Allow line editing when reading input from the command line

为君一笑 提交于 2019-12-06 14:47:25
I already know how to get the input from user keyboard. I can use the readLine() method or let input = FileHandle.standardInput let inputData = input.availableData var text = String(data: inputData, encoding: .utf8) But the two methods get also when the user press an arrow key button. I would like to filter the input in order to remove these data. I want that the user can write something, maybe go back with the left arrow key, change something and insert the data without problem. Thanks! What you are looking for is the “line editing feature” which is provided by libedit on macOS. In order to

How can I use tie() to redirect STDOUT, STDERR only for certain packages?

*爱你&永不变心* 提交于 2019-12-06 07:59:31
I need to work with some libraries that unfortunately log diagnostic messages to STDOUT and STDERR. By using tie , I can redirect those writes to a function that captures those. Since I don't want all STDOUT and STDERR output of my programs to be captured thtough the tied handle, I'd like to do this only for certain packages. I have come up with a solution where the actual behavior is determined by looking at caller() as can be seen below, but I have the feeling that there has to be a better way... Is there a more elegant solution? package My::Log::Capture; use strict; use warnings; use 5.010;

OSX Custom extension icon Association

牧云@^-^@ 提交于 2019-12-05 12:05:51
I'm trying to get my application to display an icon for a custom file extension using the following code: <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>My Custom Extension</string> <key>CFBundleTypeRole</key> <string>Viewer</string> <key>LSItemContentTypes</key> <array> <string>com.myapp.myext</string> </array> <key>LSHandlerRank</key> <string>Owner</string> <key>NSExportableTypes</key> <array> <string>com.myapp.myext</string> </array> </dict> </array> <key>UTExportedTypeDeclarations</key> <array> <dict> <key>UTTypeIconFile</key> <string>Myicon.icns<

List all currently open file handles? [duplicate]

半世苍凉 提交于 2019-12-05 08:18:23
Possible Duplicate: check what files are open in Python Hello, Is it possible to obtain a list of all currently open file handles, I presume that they are stored somewhere in the environment. I am interested in theis function as I would like to safely handle any files that are open when a fatal error is raised, i.e. close file handles and replace potentially corrupted files with the original files. I have the handling working but without knowing what file handles are open, I am unable to implement this idea. As an aside, when a file handle is initialised, can this be inherited by another

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

对着背影说爱祢 提交于 2019-12-05 03:36:56
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 normal $-prefixed variable is used for the file handle: open(my $fh, "<", "input.txt") and also examples where a bareword is used: open(FOO, "|tr '[a-z]' '[A-Z]'"); One question is what is the name of each style as in "I am using _ _ for a filehandle" in each case? The other is, why did they start using bare words for open() in the documentation? It

perl share filehandle with threads

隐身守侯 提交于 2019-12-04 21:31:24
I've found the code below online, it seems the way the program control the loop is to check the shared variable $TERM is 0 or not. Can I share a filehandle between threads, that every thread deal with one line of a file and loop ends when the file reaches the last line? #!/usr/bin/perl use strict; use warnings; use threads 1.39; use threads::shared; use Thread::Queue; ### Global Variables ### # Maximum working threads my $MAX_THREADS = 10; # Flag to inform all threads that application is terminating my $TERM :shared = 0; # Threads add their ID to this queue when they are ready for work # Also,