summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2018-04-21 10:40:07 +0200
committerPeter Bex <peter@more-magic.net>2018-04-21 10:40:07 +0200
commite0a136839ff1f359f01320e2c3e32bae0164b785 (patch)
treeda976ea1a338a089357670956e1317e26e98bd40
parent512af2ee5a33c3001f74a60f9c61dd3a08137276 (diff)
downloadscsh-process-e0a136839ff1f359f01320e2c3e32bae0164b785.tar.gz
Make ">" redirect truncate existing files
Thanks to Joerg Wittenberger
-rw-r--r--scsh-process.scm7
-rw-r--r--tests/run.scm10
2 files changed, 14 insertions, 3 deletions
diff --git a/scsh-process.scm b/scsh-process.scm
index c5a286c..f675a2c 100644
--- a/scsh-process.scm
+++ b/scsh-process.scm
@@ -415,9 +415,10 @@
((_ (> ?file-name)) (setup-redirection (> 1 ?file-name)))
((_ (>> ?file-name)) (setup-redirection (>> 1 ?file-name)))
((_ (> ?fd ?file-name))
- (duplicate-fileno (file-open (maybe->string `?file-name)
- (fx+ open/wronly open/creat))
- `?fd))
+ (duplicate-fileno
+ (file-open (maybe->string `?file-name)
+ (fx+ (fx+ open/wronly open/creat) open/trunc))
+ `?fd))
((_ (>> ?fd ?file-name))
(duplicate-fileno (file-open (maybe->string `?file-name)
(fx+ open/wronly (fx+ open/append open/creat)))
diff --git a/tests/run.scm b/tests/run.scm
index 96d49eb..9bf2c75 100644
--- a/tests/run.scm
+++ b/tests/run.scm
@@ -143,6 +143,16 @@
(test "Subprocess writing to a file"
"hi, there\n"
(begin (run (echo "hi, there") (> ,the-outfile))
+ (read-all the-outfile)))
+
+ (test "Appending to the file"
+ "hi, there\nhi, again\n"
+ (begin (run (echo "hi, again") (>> ,the-outfile))
+ (read-all the-outfile)))
+
+ (test "Writing to the file truncates"
+ "hi, truncated\n"
+ (begin (run (echo "hi, truncated") (> ,the-outfile))
(read-all the-outfile))))
(delete-file* "outfile")