Hello all,
I was hoping for this program to redirect the output of the forked process into a file -
(define program (list path: "ls" stdout-redirection: #f arguments: (list "-l")))
(with-output-to-file (list path: "output.txt") (lambda () (open-process program)))
But that does not seem to happen. I am not sure what I am missing here.
Regards, Kashyap
Afficher les réponses par date
When stdout-redirection: is #f, the output of the process will go to the POSIX stdout.
When it is #t, the output of the process will go to the process port, and you can read from that port to get the output.
For example:
(define program (list path: "ls" stdout-redirection: #t arguments: (list "-l")))
(pp (call-with-input-process program (lambda (port) (read-line port #f))))
Marc
On Mar 20, 2018, at 10:28 AM, C K Kashyap ckkashyap@gmail.com wrote:
Hello all,
I was hoping for this program to redirect the output of the forked process into a file -
(define program (list path: "ls" stdout-redirection: #f arguments: (list "-l")))
(with-output-to-file (list path: "output.txt") (lambda () (open-process program)))
But that does not seem to happen. I am not sure what I am missing here.
Regards, Kashyap
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Got it - so if I have to redirect to a file, I could do this - (with-output-to-file "output.txt" (lambda () (display (call-with-input-process program (lambda (port) (read-line port #f))))))
Although, I'd like to understand why stdout-redirection: #f outputs to stdout and not the current output port. Is that a problem?
Regards, Kashyap
On Tue, Mar 20, 2018 at 8:30 AM, Marc Feeley feeley@iro.umontreal.ca wrote:
When stdout-redirection: is #f, the output of the process will go to the POSIX stdout.
When it is #t, the output of the process will go to the process port, and you can read from that port to get the output.
For example:
(define program (list path: "ls" stdout-redirection: #t arguments: (list "-l")))
(pp (call-with-input-process program (lambda (port) (read-line port #f))))
Marc
On Mar 20, 2018, at 10:28 AM, C K Kashyap ckkashyap@gmail.com wrote:
Hello all,
I was hoping for this program to redirect the output of the forked
process into a file -
(define program (list path: "ls" stdout-redirection: #f arguments: (list "-l")))
(with-output-to-file (list path: "output.txt") (lambda () (open-process program)))
But that does not seem to happen. I am not sure what I am missing here.
Regards, Kashyap
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
2018-03-21 1:54 GMT+08:00 C K Kashyap ckkashyap@gmail.com:
Got it - so if I have to redirect to a file, I could do this - (with-output-to-file "output.txt" (lambda () (display (call-with-input-process program (lambda (port) (read-line port #f))))))
Although, I'd like to understand why stdout-redirection: #f outputs to stdout and not the current output port.
Stdout is the current output port of the host OS environment, so this argument specifies that Gambit should leave it untouched.
Is that a problem?
That depends on you.
Thanks Adam,
I was wondering then, what would be a better way to do this - (with-output-to-file "output.txt" (lambda () (display (call-with-input-process program (lambda (port) (read-line port #f))))))
If I understand it right, this requires an extra read and write. If Gambit lets the port be overridden by the surrounding with-output-to-file, perhaps the whole thing could be achieved without the extra read and write. Hence my question was more about whether there is a problem with this approach that I am not able to see.
Regards, Kashyap
On Tue, Mar 20, 2018 at 5:26 PM, Adam adam.mlmb@gmail.com wrote:
2018-03-21 1:54 GMT+08:00 C K Kashyap ckkashyap@gmail.com:
Got it - so if I have to redirect to a file, I could do this - (with-output-to-file "output.txt" (lambda () (display (call-with-input-process program (lambda (port) (read-line port #f))))))
Although, I'd like to understand why stdout-redirection: #f outputs to stdout and not the current output port.
Stdout is the current output port of the host OS environment, so this argument specifies that Gambit should leave it untouched.
Is that a problem?
That depends on you.
2018-03-21 9:03 GMT+08:00 C K Kashyap ckkashyap@gmail.com:
Thanks Adam,
I was wondering then, what would be a better way to do this - (with-output-to-file "output.txt" (lambda () (display (call-with-input-process program (lambda (port) (read-line port #f))))))
If I understand it right, this requires an extra read and write. If Gambit lets the port be overridden by the surrounding with-output-to-file, perhaps the whole thing could be achieved without the extra read and write. Hence my question was more about whether there is a problem with this approach that I am not able to see.
If you're trying to achieve "/bin/sh -c "program > output.txt"", then first that's not what you're doing here, and second, you would benefit of using read/write-subu8vector for the forwarding as it's faster. Or you could ask the OS to do it using |shell-command|.
You need to clarify your problem specification and code example for anyone to be able to give you more guidance.