Perl: the Markov chain saw | |
PerlMonks |
Re: Running Perl in an Expect loopby haukex (Archbishop) |
on Dec 15, 2016 at 07:40 UTC ( [id://1177824]=note: print w/replies, xml ) | Need Help?? |
Hi StoneLeopard, What is the overall problem you are trying to solve by executing code like this? The reason I ask is because - sorry to be direct - your solution seems over-engineered. The reason your code isn't working is that the standard perl process does not implement a REPL (Read-Eval-Print Loop), it only executes a script once it has read and parsed the entire file (the exception being BEGIN blocks, but I don't think that's appropriate here either). You can try this out yourself by doing manually what Expect is doing: at the command line run perl, type in some code, and you'll see it won't be executed until you send an EOF. Now, you could have the child process run a REPL loop (from CPAN, from PerlMonks), but even then the question is, why not do away with the child process entirely and just use eval directly? If you need to capture the executed code's STDOUT, you could use Capture::Tiny. Remember, executing any code from untrusted sources is a huge security hole! Hope this helps,
In Section
Seekers of Perl Wisdom
|
|