summary refs log tree commit diff stats
path: root/tests/osproc/tstderr.nim
blob: 55b11eba51bf52d83c459a495c259a260702a4cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
discard """
  output: '''
start tstderr
--------------------------------------
to stderr
to stderr
--------------------------------------
'''
"""

echo "start tstderr"

import osproc, os, streams

const filename = "ta_out".addFileExt(ExeExt)

doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename)

var p = startProcess(filename, getCurrentDir() / "tests" / "osproc",
                     options={})

try:
  let stdoutStream = p.outputStream
  let stderrStream = p.errorStream
  var x = newStringOfCap(120)
  var output = ""
  while stderrStream.readLine(x.TaintedString):
    output.add(x & "\n")

  echo "--------------------------------------"
  stdout.flushFile()
  stderr.write output
  stderr.flushFile()
  echo "--------------------------------------"
  stdout.flushFile()
finally:
  p.close()