Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > fork/exec with input redirection

Reply
Thread Tools

fork/exec with input redirection

 
 
Dan Upton
Guest
Posts: n/a
 
      11-26-2007
I have a Python script that does a fork/exec, so the parent process
can get the child's PID and monitor /proc/PID/stat (on a CentOS
system). Most of my processes' command lines are straightforward
enough to do this with, but I have a handful that use < on the command
line, eg

../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
 
Reply With Quote
 
 
 
 
hdante
Guest
Posts: n/a
 
      11-27-2007
On Nov 26, 7:58 pm, "Dan Upton" <(E-Mail Removed)> wrote:
> I have a Python script that does a fork/exec, so the parent process
> can get the child's PID and monitor /proc/PID/stat (on a CentOS
> system). Most of my processes' command lines are straightforward
> enough to do this with, but I have a handful that use < on the command
> line, eg
>
> ./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"])
 
Reply With Quote
 
 
 
 
hdante
Guest
Posts: n/a
 
      11-27-2007
On Nov 27, 12:09 am, hdante <(E-Mail Removed)> wrote:
> On Nov 26, 7:58 pm, "Dan Upton" <(E-Mail Removed)> wrote:
>
>
>
> > I have a Python script that does a fork/exec, so the parent process
> > can get the child's PID and monitor /proc/PID/stat (on a CentOS
> > system). Most of my processes' command lines are straightforward
> > enough to do this with, but I have a handful that use < on the command
> > line, eg

>
> > ./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 ?
 
Reply With Quote
 
Dan Upton
Guest
Posts: n/a
 
      11-27-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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input redirection with IDLE candide Python 0 10-13-2009 02:16 PM
Input redirection in ruby Michal Suchanek Ruby 4 08-01-2008 06:47 AM
Which is faster in ASIC: 2-input AND gate or a 2-input multiplexer Weng Tianxiang VHDL 12 08-11-2005 10:50 AM
Input Drops With An Empty Input Queue Spiz Cisco 12 05-18-2005 05:28 PM
input redirection MadHatter Perl 6 10-16-2003 04:05 PM



Advertisments