By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,404 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,404 IT Pros & Developers. It's quick & easy.

fork/exec with input redirection

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
./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.