I'm trying to automate input into a command line C program (which I have no control over), it takes arguments, runs some processor intensive code (read takes a minute), then prompts to fill out form like information. I'm not sure what the best way to Input into the prompts once they become available. Are there any CPAN libraries which make this easier? How should I go about this? To clarify I'm trying to wrap this program as a library. Kind of like how Git::Wrapper Wraps git.
-
Just to be sure, did you try redirecting stdin for the said C program?Vojislav Stojkovic– Vojislav Stojkovic2012-03-03 01:29:28 +00:00Commented Mar 3, 2012 at 1:29
-
trying to wrap it as a library. I've started using IPC::Cmd, but not sure I can send to stdin while using that, so it may not work.xenoterracide– xenoterracide2012-03-03 01:47:48 +00:00Commented Mar 3, 2012 at 1:47
Add a comment
|
1 Answer
Without knowing more about the program you're trying to automate, I'd suggest you start by looking at Expect. It's also possible to do this with IPC::Run's start, pump, and finish functions, but Expect is a higher-level module. (And for a really low-level module, there's IPC::Open3 in core.)
3 Comments
brian d foy
Expect is even more cool than Perl. It was my favorite Tcl thing, and even though Perl has an equivalent module, I still like the Tcl version.
xenoterracide
as far as I can see there's no way to send commands to an exec'd program with
run_forked or at least no obvious way. Expect seems to work though, just has a learning curve.cjm
@xenoterracide, you're right. I saw
child_stdin => SCALAR and was thinking filehandle, but it's not. You can do it with IPC::Run, though.