1

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.

2
  • Just to be sure, did you try redirecting stdin for the said C program? Commented 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. Commented Mar 3, 2012 at 1:47

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.