<?xml version="1.0" encoding="windows-1252"?>
<node id="1018212" title="Passing argument into STDIN inside safe.pm reval" created="2013-02-11 13:33:22" updated="2013-02-11 13:33:22">
<type id="115">
perlquestion</type>
<author id="1005218">
gideondsouza</author>
<data>
<field name="doctext">
&lt;p&gt;So I have a little 'executor.pl' script that looks like this:&lt;/p&gt;
&lt;code&gt;
## executor.pl
use Safe;

if($ARGV[0]) {
	my $code = $ARGV[0];
	my $compartment = new Safe;
	$compartment-&gt;deny(qw(:base_io... MANY OP CODES....));
	$compartment-&gt;permit(qw(print say pack unpack require caller));
        ##I want to pass something into the STDIN for the $code reval-ed
	my $result = $compartment-&gt;reval($code);
	if ($@) {
		print "Unsafe code detected: $@";
	}
}
&lt;/code&gt;

&lt;p&gt;
And I do this to invoke executor.pl :&lt;/p&gt;

&lt;code&gt;
	open(FILE,"perl executor.pl '$code' 2&gt;&amp;1 |")
	my @output=&lt;FILE&gt;;
	my $resp = join('',@output);
&lt;/code&gt;

&lt;p&gt;&lt;strong&gt;Question: &lt;/strong&gt;Is there a way I can pass some argument into the &lt;u&gt;code being reval-ed&lt;/u&gt; as STDIN ?. So essentially I can reval some code and then pass it some known arg to its STDIN&lt;/p&gt;

&lt;p&gt;Please don't worry, this isn't any production code. I'm just doing this as a learning/curiosity exercise&lt;/p&gt;</field>
</data>
</node>
