filehandle

Delete currently loaded assembly

穿精又带淫゛_ 提交于 2020-01-01 19:13:10
问题 In my application comes with an uninstaller. Everything is working fine, except that I can't find no way to delete the uninstaller.exe file when it's all done. I tried to copy the current assembly exe into a temp directory, but the file-handle of the original file is still locked. Any ideas? 回答1: You will need to PInvoke to do this. MoveFileEx has the ability to schedule deleting the file on next reboot. If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx

How to find open global filehandles in a perl program

一个人想着一个人 提交于 2020-01-01 10:54:01
问题 I just tracked down a problem where I had to close all open filehandles for my Apache cgi script to continue. I traced the problem to Parse::RecDescent. #!/usr/bin/env perl use strict; use warnings; use feature qw/say/; $|++; print "Content-Type: text/plain\n\n"; use Parse::RecDescent; say "$$: pre-fork: ". time; if(my $pid = fork) { # parent say "$$: return immediately: ". time; } else { # child say "$$: kicked off big process: ". time; close STDIN; close STDOUT; close STDERR; # close *{

How to find open global filehandles in a perl program

ⅰ亾dé卋堺 提交于 2020-01-01 10:53:12
问题 I just tracked down a problem where I had to close all open filehandles for my Apache cgi script to continue. I traced the problem to Parse::RecDescent. #!/usr/bin/env perl use strict; use warnings; use feature qw/say/; $|++; print "Content-Type: text/plain\n\n"; use Parse::RecDescent; say "$$: pre-fork: ". time; if(my $pid = fork) { # parent say "$$: return immediately: ". time; } else { # child say "$$: kicked off big process: ". time; close STDIN; close STDOUT; close STDERR; # close *{

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

℡╲_俬逩灬. 提交于 2020-01-01 08:50:38
问题 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 ZIPPED filehandle to the file "zipped.gz". I know how to use "import gzip" to do this in Python like this: import gzip zipped = gzip.open("zipped.gz", 'wb') zipped.write("Hello world\n") However, that is extremely slow. According to the profiler, using

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

删除回忆录丶 提交于 2019-12-31 10:36:20
问题 This question already has an answer here : Which file is Perl's diamond operator (null file handle) currently reading from? (1 answer) Closed 6 years ago . 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

How can I suppress STDOUT temporarily in a Perl program?

两盒软妹~` 提交于 2019-12-30 04:56:11
问题 Is there any easy way to tell perl "now ignore everything that is printed"? I have to call a procedure in an external Perl module, but the procedure prints a lot of unnecessary information (all through standard print ). I know select can be used to redirect it somehow, but I am not too wise from reading perldoc on it. edit : I found the answer sooner, but I will add an example to make it clearer (but not much I guess) use TectoMT::Scenario; use TectoMT::Document; sub tagDocuments { my

How can I pass a filehandle to Perl Expect's log_file function?

我的未来我决定 提交于 2019-12-25 04:42:53
问题 I feel stupid for asking this, but I've tried a couple things and I'm not sure where to go with it. From the Expect.pm documentation: $object->log_file("filename" | $filehandle | \&coderef | undef) Log session to a file. All characters send to or received from the spawned process are written to the file. I'd like to pass the $filehandle to log_file. However, when I tried this: open (LOG, ">>" .$opt{l}); my $sess = Expect->spawn("telnet $ip"); $sess->log_file(LOG) I get a file named 'LOG' in

Swift. How to append text line to top of file.txt?

天大地大妈咪最大 提交于 2019-12-24 19:15:45
问题 I am implementing a small logger, in which I am writing to a TXT file. I wanted the last event to be at the top of the file but I'm having trouble getting this to work. All examples on the internet are using "fileHandle.seekToEndOfFile()" to write at the end of the file. This is what I have: private static func writeToFile(text: String) { guard let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first else { return } guard let writePath = NSURL

Thread communication via printf and scanf (linux)

南笙酒味 提交于 2019-12-24 09:15:40
问题 Working in Linux and using C++. I have a program which initiates a thread. I need the main thread and the child thread to communicate via printf and scanf (the code for both threads uses scanf and printf and assumes that it communicates with stdin and stdout. I must keep it that way). I managed to override printf and scanf, so I have total control over these functions (and I can identify the calling thread using *pthread_self*). What remains to be done is to create 2 file handles, one for

perl how can I append STDOUT of list form system call of perl script to a file

萝らか妹 提交于 2019-12-23 23:09:55
问题 My bosswrap.pl will generate arbitrary arrays containing whitespace in the elements. It repeatedly sends the array by a system call to wrapped.pl , which creates STDOUT based on the array. Subsequently, bosswrap.pl must append the STDOUT of wrapped.pl to a file which bosswrap.pl controls. That is where I am stuck. First wrapped.pl : #!/usr/bin/perl use strict; use warnings; print "inside $0\n"; my $countarrayelements=0; for my $item ( @ARGV ) { $countarrayelements++; print "