fork/exec with input redirection

D

Dan Upton

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
 
H

hdante

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"])
 
H

hdante

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 ?
 
D

Dan Upton

./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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top