[racket] actions with a proc

From: Maleval Sebastien (sebastien.maleval at gmail.com)
Date: Tue Jul 3 15:06:19 EDT 2012

Le 03/07/2012 18:53, Vincent St-Amour a écrit :
> At Tue, 03 Jul 2012 14:55:00 +0200,
> Maleval Sebastien wrote:
>> Hi, I'm trying to use file functions, and I asked myself if it was
>> possible to execute, and in the same time, write in a ".exe" file.
>> Someone know what function I must use for this ?
> As far as I know, Windows does not let you write in a running
> executable.
>
> Taking a step back, what are you tring to do?
>
> Vincent
>

I try to file a corrupted file (or make it unusable - not readable) 
during its execution. But I've always the same probleme.  Windows does 
not let me write.
Would there another solution?

See my code :

#lang racket

(define f "file.exe")
(define listOfByte '())

(define (readByteOnFile fileName)
   (call-with-input-file fileName
     (lambda (p-in)
       (define (iter)
         (let ((x (read-byte p-in)))
           (if (eof-object? x)
               (void (set! listOfByte (reverse listOfByte)))
               (begin
                 (set! listOfByte (cons x listOfByte))
                 (iter)))))
       (iter))))

(define (writeByteOnFile fileName L)
   (port-try-file-lock? (open-output-file f #:exists 'replace) 'shared)
   (call-with-output-file fileName
     (lambda (p-out)
       (define (iter L)
         (if (empty? L)
             (printf "Fini")
             (begin
               (write-byte (car L) p-out)
               (iter (rest L)))))
       (iter L))
     #:exists 'append))

(define (executeFile fileName)
   (shell-execute "open" f "" (current-directory) 'sw_shownormal))

In the order I read Bytes, Execute file and error when writting random 
Bytes (not in my code), I must find an other solution.
(writeByteOnFile fileName L) is function to re-create my file.



Posted on the users mailing list.