← nimrepo

shell and fs

01611866603bc1d01693e1511922a32ae3d73557 · ovidiucs · Jan 31, 2019 11:49

+15 · 1 file changed

  • shellandfs.nim +15 −0
diff --git a/shellandfs.nim b/shellandfs.nim
new file mode 100644
index 0000000..357ac91
--- /dev/null
+++ b/shellandfs.nim
@@ -0,0 +1,15 @@
+import terminal #isatty, styledEcho
+import strformat #fmt, 
+import times
+
+if isatty(stdout): # ./stdout_to_file
+  echo "This is output to the terminal."
+else:              # ./stdout_to_file | cat
+  const
+    logFileName = "log.txt"
+  let
+    # https://github.com/jasonrbriggs/nimwhistle/blob/183c19556d6f11013959d17dfafd43486e1109e5/tests/cgitests.nim#L15
+    logFile = open(logFileName, fmWrite)
+  stdout = logFile
+  echo fmt"This is output to the {logFileName} file."
+  echo fmt"- Run using nim {NimVersion} on {now()}."
\ No newline at end of file