Skip to content

Commit

Permalink
🐛 高確率でコマンド実行時にクラッシュする不具合を修正 #15
Browse files Browse the repository at this point in the history
  • Loading branch information
jiro4989 committed Dec 9, 2019
1 parent 62ade3f commit cb81610
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions websh_server/src/websh_server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ proc info(msgs: varargs[string, `$`]) =
proc readStream(strm: var Stream): string =
defer: strm.close()
var lines: seq[string]
var line: string
while strm.readLine(line):
for line in strm.lines:
lines.add(line)
result = lines.join("\n")

Expand All @@ -30,14 +29,16 @@ proc runCommand(command: string, args: openArray[string]): (string, string) =
var
p = startProcess(command, args = args, options = {poUsePath})
stdoutStr, stderrStr: string
defer: p.close()
while p.running():
block:
var strm = p.outputStream
stdoutStr = strm.readStream()
block:
var strm = p.errorStream
stderrStr = strm.readStream()
p.close()
# プロセスが処理完了するまで待機
sleep 10
block:
var strm = p.outputStream
stdoutStr = strm.readStream()
block:
var strm = p.errorStream
stderrStr = strm.readStream()
result = (stdoutStr, stderrStr)

router myrouter:
Expand Down

0 comments on commit cb81610

Please sign in to comment.