471,354 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

fork/exec with input redirection

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
Nov 26 '07 #1
3 2072
On Nov 26, 7:58 pm, "Dan Upton" <up...@virginia.eduwrote:
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"])
Nov 27 '07 #2
On Nov 27, 12:09 am, hdante <hda...@gmail.comwrote:
On Nov 26, 7:58 pm, "Dan Upton" <up...@virginia.eduwrote:
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 ?
Nov 27 '07 #3
./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).
Nov 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Benoit Dejean | last post: by
21 posts views Thread by anshul1806 | last post: by
4 posts views Thread by Andreas.Burman | last post: by
3 posts views Thread by thrillseekersforever | last post: by
1 post views Thread by rickcasey | last post: by
2 posts views Thread by Rafael Giannetti Viotti | last post: by
23 posts views Thread by Maarten | last post: by
5 posts views Thread by boddah | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.