I am trying using osproc to reload but I can't seem to get stdout from 
server.exe. I'd like to be able to see the debug msg from jester.
    
    
    import std/osproc
    import std/os
    import std/tables
    import std/times
    import std/strutils
    
    discard execCmd("nim c server.nim")
    var p = startProcess("server.exe", options={poUsePath,poStdErrToStdOut})
    
    proc atExit() {.noconv.} =
        p.terminate()
        p.close()
        quit(0)
    setControlCHook(atExit)
    
    var files: Table[string, Time] = {"path": 
getLastModificationTime(".")}.toTable
    while true:
        sleep(300)
        for path in walkDirRec("."):
            if ".git" in path:
                continue
            var (_, _, ext) = splitFile(path)
            if ext in [".scss", ".sass", ".less", ".styl", ".pcss", 
".postcss",".exe",".db"]:
                continue
            if files.hasKey(path):
                if files[path] != getLastModificationTime(path):
                    echo("File changed: " & path)
                    p.terminate()
                    p.close()
                    echo "Terminating Server... Rebuilding"
                    echo execCmd("nim c server.nim")
                    p = startProcess("server.exe", 
options={poUsePath,poStdErrToStdOut})
                files[path] = getLastModificationTime(path)
            else:
                if absolutePath(path) in [absolutePath("runserver.nim")]:
                    continue
                files[path] = getLastModificationTime(path)
    
    
    Run

Reply via email to