The following two simple programs work together under LInux - but not Windows 10
sayhello.nim:
echo "Hello World"
echo "Bye Bye"
and runhello.nim
import osproc
var exeName = "sayhello"
var tstprc = startProcess(exeName,"",[],nil,{poInteractive})
var tstouthdl = tstprc.outputHandle()
echo "tstouthdl=",tstouthdl.repr()
var tstout:File
if not tstout.open(tstouthdl):
quit("Cannot Open tstout")
var outline = tstout.readLine()
echo "outline=",outline
Both machines are using nim 0.19 and a vanilla nim c -r sourcename compiling command.
What options/arguments/command-variations do I use to get the Windows 10 version to work?
Thanks
Found a workaround by looking in osproc source:
import osproc, streams
var exeName = "sayhello"
when defined(windows):
exeName &= ".exe."
echo "exeName=",exeName
var tstprc = startProcess(exeName,"",[],nil,{
poEvalCommand})
var tstouthdl = tstprc.outputStream()
var line = newStringOfCap(120).TaintedString
while true:
if tstouthdl.readLine(line):
echo "piped:",line
elif not running(tstprc): break
close(tstprc)
This uses a Stream instead of a FileHandle and a pre-created line buffer.
Still not sure why a Stream works but a File does not! The different po-option did not cure the problem Adding the exe file name extension to exeName did not help either.
Thank you for sharing. :) import osproc, streams
var exeName = "sayhello"
echo "exeName=",exeName
var line = newStringOfCap(120).TaintedString
elif not running(tstprc): break