I'm wanting to start a process (like popen) and read it's output asyncronously. It seems startProcess is what I need to use. I started with this simple program but got stumped.
import osproc, streams
var MyProc = startProcess("/usr/bin/find", "", ["/", "-print"] )
var MyStdout = MyProc.outputStream()
while true:
var line: TaintedString
if readLine(MyStdout, line):
echo("Line '" & line & "'")
$ nim c -d:useSysAssert -d:useGcAssert -d:taintMode --checks:on readfeeds.nim
/etc/nim.cfg(45, 2) Hint: added path: '/home/jay/.babel/pkgs/' [Path]
/etc/nim.cfg(46, 2) Hint: added path: '/home/jay/.nimble/pkgs/' [Path]
Hint: used config file '/etc/nim.cfg' [Conf]
Hint: system [Processing]
Hint: readfeeds [Processing]
Hint: osproc [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: os [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: strtabs [Processing]
Hint: hashes [Processing]
Hint: streams [Processing]
Hint: cpuinfo [Processing]
Hint: linux [Processing]
lib/nim/pure/osproc.nim(263, 13) Warning: startCmd is deprecated [Deprecated]
lib/nim/pure/osproc.nim(291, 19) Warning: startCmd is deprecated [Deprecated]
lib/nim/pure/osproc.nim(301, 14) Warning: startCmd is deprecated [Deprecated]
lib/nim/pure/osproc.nim(623, 4) Warning: use 'defer'; standalone 'finally' is deprecated [Deprecated]
lib/nim/pure/osproc.nim(647, 4) Warning: use 'defer'; standalone 'finally' is deprecated [Deprecated]
lib/nim/pure/osproc.nim(748, 4) Warning: use 'defer'; standalone 'finally' is deprecated [Deprecated]
lib/nim/pure/osproc.nim(779, 6) Warning: raiseOSError is deprecated [Deprecated]
lib/nim/pure/osproc.nim(825, 20) Warning: undeclared conditional symbol; use --symbol to declare it: uClibc [User]
lib/nim/pure/osproc.nim(952, 10) Warning: startCmd is deprecated [Deprecated]
lib/nim/pure/osproc.nim(701, 9) Hint: 'osproc.startProcessAuxSpawn(data: TStartProcessData): TPid' is declared but not used [XDeclaredButNotUsed]
CC: readfeeds
[Linking]
Hint: operation successful (18343 lines compiled; 0.494 sec total; 31.317MB) [SuccessX]
then I get this error:
$ readfeeds
Traceback (most recent call last)
readfeeds.nim(9) readfeeds
streams.nim(171) readLine
SIGSEGV: Illegal storage access. (Try to compile with -d:useSysAssert -d:useGcAssert for details.)
If I don't use those compilation flags I get the same error. Can anyone point me in the direction of the problem? Thanks.You need to initialise line I think.
Also, your variable names shouldn't start with an uppercase letter.