fork/exec with input redirection

Dan Upton upton at virginia.edu
Tue Nov 27 15:45:46 EST 2007


> > > ./gobmk_base.linux_x86 --quiet --mode gtp < 13x13.tst
> >
> > > The only thing I could really think of to try was
> >
> > >    os.execv("./gobmk_base.linux_x86", ["./gobmk_base.linux_x86",
> > > "--quiet", "--mode", "gtp", "<", "13x13.tst"])
> >
> > > but this apparently doesn't work.  Is there some other way to
> > > accomplish what I'm going for?
> >
> > > Thanks,
> > > -dan
> >
> >  IIRC,
> >
> >  if os.fork() == 0:
> >    new_stdin = os.open('13x13.tst')
> >    os.dup2(new_stdin, sys.stdin.fileno())
> >    os.close(new_stdin)
> >    os.execv("./gobmk_base.linux_x86", ["./gobmk_base.linux_x886", "--
> > quiet", "--mode", "gtp"])
>
>  Maybe a sys.stdin.flush() just to be sure ?
>

Thanks, that did the trick (well, os.open('13x13.tst', os.O_RDONLY),
but you know... close enough).



More information about the Python-list mailing list