-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The startProcess
API is incomplete
#7999
Comments
Another useful consideration is async friendliness, that is, ensuring all relevant handles are accessible to be wrapped into async-flavoured api. |
Partially related: execCmd / execCmdEx also have a different API from startProcess and execProcess , e.g. they don't support env and a timeout. |
/cc @zah I think we could take inspiration from that design, but with some modifcations to take advantage of Nim language.
in Nim this could be:
|
if you've ever seen garbled cgen errors like this: /Users/timothee/git_clone/nim/timn/build/nimcache/@mt11253.nim.c:94:2: error: use of /Users/timothee/git_clone/nim/timn/build/nimcache/@mt11253b.nim.cundeclared:87:2: error: identifieruse 'Foo'of undeclared
identifier 'Foo'
Foo a; Foo a;
^ ^
/Users/timothee/git_clone/nim/timn/build/nimcache/@mt11253b.nim.c:89:22: error: use of undeclared identifier 'a'
nimZeroMem((void*)(&a), sizeof(Foo)); it's related to this. the problem is that the fix is to implement proper stream capture, and a user supplied callback that handles what to do with each captured line/piece of stdout/stderr stream. minimized example# main.nim:
when true:
import osproc, strformat, random, os
proc main()=
let file = currentSourcePath.parentDir / "t11254b.nim"
let outFile="/tmp/z01"
const nim = getCurrentCompilerExe()
doAssert execShellCmd(fmt"{nim} c -o:{outFile} {file}")==0
var cmds: seq[string]
let n = 3
for i in 0..<n:
cmds.add outFile
let res = execProcesses(cmds, {poUsePath, poParentStreams}) # garbled
# let res = execProcesses(cmds, {poUsePath, poParentStreams}, n=1) # ok
doAssert res == 0
main()
# t11254b.nim:
when true:
proc main=
for i in 0..<3:
stderr.write "{"
for j in 0..<10:
stderr.write $j
stderr.write "}\n"
main() output with n=1:
output with n = countProcessors():
|
Well I'm still waiting for your Nimble package that offers an osproc alternative. (The rule should still be Nimble first, fusion second.) |
@leorize ? |
At the moment
startProcess
allows you to provide flags such aspoParentStreams
andpoStdErrToStdOut
to control the behaviour of standard input and output stream of the new process.This limits the usage to two possible outcomes:
startProcess
for all of the streams.There are no options for inheriting only some of the streams or passing in already created pipes to be used.
The API can be further enhanced by introducing the notion of process groups, which allows you to manage indirect sub-processes (e.g. when launching a script that will execute multiple sub-commands):
https://www.boost.org/doc/libs/1_65_0/doc/html/boost_process/tutorial.html#boost_process.tutorial.group
The text was updated successfully, but these errors were encountered: